Skip to content

Commit f6efc1c

Browse files
committed
Initial commit
0 parents  commit f6efc1c

11 files changed

+178
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
8+
[*.{c,h}]
9+
indent_style = tab
10+
indent_size = 4
11+
12+
[Makefile]
13+
indent_style = tab

.github/workflows/installcheck.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
defaults:
10+
run:
11+
shell: sh
12+
13+
strategy:
14+
matrix:
15+
pgversion:
16+
- 16
17+
- 15
18+
- 14
19+
- 13
20+
- 12
21+
22+
env:
23+
PGVERSION: ${{ matrix.pgversion }}
24+
25+
steps:
26+
- name: checkout
27+
uses: actions/checkout@v4
28+
29+
- name: install pg
30+
run: |
31+
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -v $PGVERSION -p -i
32+
sudo -u postgres createuser -s "$USER"
33+
34+
- name: build
35+
run: |
36+
make PROFILE="-Werror"
37+
sudo -E make install
38+
39+
- name: test
40+
run: |
41+
sudo pg_conftool set shared_preload_libraries postgresql_extension_template
42+
sudo pg_ctlcluster $PGVERSION main restart
43+
make installcheck
44+
45+
- name: show regression diffs
46+
if: ${{ failure() }}
47+
run: |
48+
cat regression.diffs

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Compilation artifacts
2+
.deps/
3+
*.bc
4+
*.o
5+
*.so
6+
7+
# Regression Tests Output
8+
results/
9+
regression.*

LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright (c) 2023, CYBERTEC PostgreSQL International GmbH
2+
3+
Permission to use, copy, modify, and distribute this software and its
4+
documentation for any purpose, without fee, and without a written agreement is
5+
hereby granted, provided that the above copyright notice and this paragraph and
6+
the following two paragraphs appear in all copies.
7+
8+
IN NO EVENT SHALL CYBERTEC PostgreSQL International GmbH BE LIABLE TO ANY PARTY
9+
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
10+
LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
11+
EVEN IF CYBERTEC PostgreSQL International GmbH HAS BEEN ADVISED OF THE
12+
POSSIBILITY OF SUCH DAMAGE.
13+
14+
CYBERTEC PostgreSQL International GmbH SPECIFICALLY DISCLAIMS ANY WARRANTIES,
15+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16+
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
17+
IS" BASIS, AND CYBERTEC PostgreSQL International GmbH HAS NO OBLIGATIONS TO
18+
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PG_CONFIG ?= pg_config
2+
3+
EXTENSION = postgresql_extension_template
4+
MODULE_big = postgresql_extension_template
5+
OBJS = postgresql_extension_template.o
6+
DATA = postgresql_extension_template--1.0.sql
7+
REGRESS = postgresql_extension_template
8+
# To provide your README.md as docs, create a symlink like that:
9+
#
10+
# `ln -s README.md extension_name.md`
11+
#
12+
# And uncomment the following line:
13+
#DOCS = extension_name.md
14+
15+
USE_PGXS = 1
16+
ifdef USE_PGXS
17+
PGXS := $(shell $(PG_CONFIG) --pgxs)
18+
include $(PGXS)
19+
else
20+
subdir = contrib/pg_show_plans
21+
top_builddir = ../..
22+
include $(top_builddir)/src/Makefile.global
23+
include $(top_srcdir)/contrib/contrib-global.mk
24+
endif
25+

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# PostgreSQL Extension Template
2+
3+
This is a template repository for a PostgreSQL C extension. This repository
4+
includes:
5+
6+
* [EditorConfig](https://editorconfig.org/) to set C indentation to 4 space
7+
tabs, works with all text editors and GitHub.
8+
* GitHub Action to run `make installcheck` against all supported PostgreSQL
9+
server major versions.
10+
* Proper license file that you do not have to worry about.
11+
* ~10 lines boilerplate C code.
12+
* Regression tests.
13+
* `Makefile` for `PGXS`.
14+
15+
# USAGE
16+
17+
This is the simplest possible working extension, you can install it and run
18+
regression tests:
19+
20+
```bash
21+
git clone [email protected]:cybertec-postgresql/postgresql_extension_template.git your-extension-name
22+
cd your-extension-name
23+
make
24+
make install
25+
make installcheck
26+
```
27+
28+
At this point everything is pre-configured, just make your edits.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE EXTENSION postgresql_extension_template;
2+
SELECT my_function();
3+
my_function
4+
---------------------------
5+
Hello from my_function()!
6+
(1 row)
7+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* postgresql_extension_template--1.0.sql */
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use "CREATE EXTENSION pg_show_plans" to load this file. \quit
5+
6+
CREATE FUNCTION my_function()
7+
RETURNS cstring
8+
AS 'MODULE_PATHNAME'
9+
LANGUAGE C;

postgresql_extension_template.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "postgres.h"
2+
#include "fmgr.h"
3+
4+
PG_MODULE_MAGIC;
5+
6+
Datum my_function(PG_FUNCTION_ARGS);
7+
PG_FUNCTION_INFO_V1(my_function);
8+
9+
Datum
10+
my_function(PG_FUNCTION_ARGS)
11+
{
12+
PG_RETURN_CSTRING("Hello from my_function()!");
13+
}

postgresql_extension_template.control

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# postgresql_extension_template extension
2+
comment = 'Briefly describe your extension here'
3+
default_version = '1.0'
4+
module_pathname = '$libdir/postgresql_extension_template'
5+
relocatable = true

0 commit comments

Comments
 (0)