Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kovmir committed Nov 7, 2023
0 parents commit f6efc1c
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

[*.{c,h}]
indent_style = tab
indent_size = 4

[Makefile]
indent_style = tab
48 changes: 48 additions & 0 deletions .github/workflows/installcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

defaults:
run:
shell: sh

strategy:
matrix:
pgversion:
- 16
- 15
- 14
- 13
- 12

env:
PGVERSION: ${{ matrix.pgversion }}

steps:
- name: checkout
uses: actions/checkout@v4

- name: install pg
run: |
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -v $PGVERSION -p -i
sudo -u postgres createuser -s "$USER"
- name: build
run: |
make PROFILE="-Werror"
sudo -E make install
- name: test
run: |
sudo pg_conftool set shared_preload_libraries postgresql_extension_template
sudo pg_ctlcluster $PGVERSION main restart
make installcheck
- name: show regression diffs
if: ${{ failure() }}
run: |
cat regression.diffs
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Compilation artifacts
.deps/
*.bc
*.o
*.so

# Regression Tests Output
results/
regression.*
18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright (c) 2023, CYBERTEC PostgreSQL International GmbH

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose, without fee, and without a written agreement is
hereby granted, provided that the above copyright notice and this paragraph and
the following two paragraphs appear in all copies.

IN NO EVENT SHALL CYBERTEC PostgreSQL International GmbH BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
EVEN IF CYBERTEC PostgreSQL International GmbH HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

CYBERTEC PostgreSQL International GmbH SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
IS" BASIS, AND CYBERTEC PostgreSQL International GmbH HAS NO OBLIGATIONS TO
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
PG_CONFIG ?= pg_config

EXTENSION = postgresql_extension_template
MODULE_big = postgresql_extension_template
OBJS = postgresql_extension_template.o
DATA = postgresql_extension_template--1.0.sql
REGRESS = postgresql_extension_template
# To provide your README.md as docs, create a symlink like that:
#
# `ln -s README.md extension_name.md`
#
# And uncomment the following line:
#DOCS = extension_name.md

USE_PGXS = 1
ifdef USE_PGXS
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/pg_show_plans
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif

28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# PostgreSQL Extension Template

This is a template repository for a PostgreSQL C extension. This repository
includes:

* [EditorConfig](https://editorconfig.org/) to set C indentation to 4 space
tabs, works with all text editors and GitHub.
* GitHub Action to run `make installcheck` against all supported PostgreSQL
server major versions.
* Proper license file that you do not have to worry about.
* ~10 lines boilerplate C code.
* Regression tests.
* `Makefile` for `PGXS`.

# USAGE

This is the simplest possible working extension, you can install it and run
regression tests:

```bash
git clone [email protected]:cybertec-postgresql/postgresql_extension_template.git your-extension-name
cd your-extension-name
make
make install
make installcheck
```

At this point everything is pre-configured, just make your edits.
7 changes: 7 additions & 0 deletions expected/postgresql_extension_template.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE EXTENSION postgresql_extension_template;
SELECT my_function();
my_function
---------------------------
Hello from my_function()!
(1 row)

9 changes: 9 additions & 0 deletions postgresql_extension_template--1.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* postgresql_extension_template--1.0.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_show_plans" to load this file. \quit

CREATE FUNCTION my_function()
RETURNS cstring
AS 'MODULE_PATHNAME'
LANGUAGE C;
13 changes: 13 additions & 0 deletions postgresql_extension_template.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "postgres.h"
#include "fmgr.h"

PG_MODULE_MAGIC;

Datum my_function(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(my_function);

Datum
my_function(PG_FUNCTION_ARGS)
{
PG_RETURN_CSTRING("Hello from my_function()!");
}
5 changes: 5 additions & 0 deletions postgresql_extension_template.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# postgresql_extension_template extension
comment = 'Briefly describe your extension here'
default_version = '1.0'
module_pathname = '$libdir/postgresql_extension_template'
relocatable = true
3 changes: 3 additions & 0 deletions sql/postgresql_extension_template.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE EXTENSION postgresql_extension_template;

SELECT my_function();

0 comments on commit f6efc1c

Please sign in to comment.