Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Éric Lemoine committed Apr 12, 2017
0 parents commit 2d161e3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
EXTDIR=$(shell pg_config --sharedir)/extension

install:
install -m 0644 workalendar.control $(EXTDIR)
install -m 0644 workalendar--1.0.0.sql $(EXTDIR)
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Workalendar PostgreSQL extension

Install the `workalendar` Python package:

```shell
$ pip install workalendar # may be installed in a virtual env
```

Create extension in database:

```sql
CREATE EXTENSION IF NOT EXISTS workalendar CASCADE;
```

Activate virtual env if `workalendar` was installed in a virtual env:

```sql
SELECT workalendar.workon('/patch/to/virtual/env');
```

Get the french holidays for a given year:

```
SELECT * from workalendar.holidays(2017);
```
27 changes: 27 additions & 0 deletions workalendar--1.0.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION workalendar" to load this file. \quit

CREATE OR REPLACE FUNCTION workon(venv text)
RETURNS void AS
$BODY$
import os
activate_this = os.path.join(venv, 'bin', 'activate_this.py')
exec(open(activate_this).read(), dict(__file__=activate_this))
$BODY$
LANGUAGE plpython3u VOLATILE;

CREATE TYPE holiday AS (
date date,
name text
);

CREATE OR REPLACE FUNCTION holidays(year int)
RETURNS SETOF holiday AS
$BODY$
from datetime import date
from workalendar.europe import France
cal = France()
for holiday in cal.holidays(year):
yield holiday
$BODY$
LANGUAGE plpython3u VOLATILE;
7 changes: 7 additions & 0 deletions workalendar.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# workalendar extension
comment = 'workalendar extension'
default_version = '1.0.0'
relocatable = false
superuser = false
schema = 'workalendar'
requires = 'plpython3u'

0 comments on commit 2d161e3

Please sign in to comment.