-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Éric Lemoine
committed
Apr 12, 2017
0 parents
commit 2d161e3
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |