Skip to content

Commit fbdeb1c

Browse files
authored
Merge pull request #99 from jrochel/ocsipersist-pgsql
PostgreSQL backend for Ocsipersist
2 parents bad9c14 + 1823669 commit fbdeb1c

File tree

16 files changed

+390
-30
lines changed

16 files changed

+390
-30
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Libraries:
2323
* tyxml (need version 3)
2424
* ipaddr (need version >= 2.1)
2525
* ocamlsqlite3 (tested with 2.0.2) OR
26+
* pgocaml (tested with 2.3) OR
2627
* dbm (tested with 1.0)
2728

2829

configure

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ set_defaults () {
7878
enable_debug=1
7979
enable_annot=1
8080
with_sqlite=1
81+
with_pgsql=1
8182
with_camlzip=1
8283
with_dbm=1
8384
with_preempt=1
@@ -107,7 +108,7 @@ full_pwd=`pwd`
107108

108109
## Which options exist? eoptions for enable/disable, woptions for with/without:
109110
eoptions="debug annot natdynlink"
110-
woptions="sqlite dbm camlzip preempt"
111+
woptions="pgsql sqlite dbm camlzip preempt"
111112

112113
print_options () {
113114
for opt in $eoptions; do
@@ -184,6 +185,7 @@ usage: ./configure [ options ]
184185
--enable-natdynlink, --disable-natdynlink Enable/disable nativecode dynamic linking
185186
186187
--with-sqlite, --without-sqlite Compile ocsipersist with SQLite for persistent storage
188+
--with-pgsql, --without-pgsql Compile ocsipersist with PostgreSQL for persistent storage
187189
--with-dbm, --without-dbm Compile ocsipersist with DBM for persistent storage
188190
--with-camlzip, --without-camlzip Compile deflatemod extension, requires camlzip
189191
@@ -424,6 +426,12 @@ check_library cryptokit "See: http://pauillac.inria.fr/~xleroy/software.html#cry
424426

425427
check_library tyxml "See: http://ocsigen.org/tyxml/"
426428

429+
# Check PostgreSQL
430+
case "$with_pgsql" in
431+
1) if test_library pgocaml; then with_pgsql=1; else with_pgsql=0; fi;;
432+
2) check_library pgocaml "https://github.com/darioteixeira/pgocaml";;
433+
esac
434+
427435
# Check Sqlite3
428436
case "$with_sqlite" in
429437
1) if test_library sqlite3; then with_sqlite=1; else with_sqlite=0; fi;;
@@ -514,6 +522,11 @@ if [ $with_sqlite -gt 0 ] ; then
514522
else
515523
with_sqlite="NO"
516524
fi
525+
if [ $with_pgsql -gt 0 ] ; then
526+
with_pgsql="YES"
527+
else
528+
with_pgsql="NO"
529+
fi
517530
if [ $with_camlzip -gt 0 ] ; then
518531
with_camlzip="YES"
519532
else
@@ -569,6 +582,9 @@ CAMLZIPNAME:=$zipname
569582
# Do you want ocsipersist with sqlite? YES/NO
570583
OCSIPERSISTSQLITE:=$with_sqlite
571584
585+
# Do you want ocsipersist with pgsql? YES/NO
586+
OCSIPERSISTPGSQL:=$with_pgsql
587+
572588
# Do you want ocsipersist with dbm? YES/NO
573589
OCSIPERSISTDBM:=$with_dbm
574590

doc/manual-wiki/config.wiki

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ Here is a simple example:
148148
</ocsigen>
149149
}}}
150150

151-
Here is another example, for use as unprivileged user toto on port 8000:
151+
Here is another example, for use as unprivileged user toto on port 8000.
152+
We use the PostgreSQL (version >= 9.5) backend for ocsipersist. Note that the
153+
ocsipersist-database under the specified name (default: "ocsipersist") needs to
154+
exist. To create it run {{{psql}}} and execute {{{CREATE TABLE ocsipersist;}}}.
152155

153156
{{{
154157
<ocsigen>
@@ -167,8 +170,14 @@ Here is another example, for use as unprivileged user toto on port 8000:
167170

168171
<extension findlib-package="ocsigenserver.ext.staticmod"/>
169172

170-
<extension findlib-package="ocsigenserver.ext.ocsipersist-sqlite"/>
171-
<!-- sqlite3.cma will be loaded automatically using findlib -->
173+
<extension findlib-package="ocsigenserver.ext.ocsipersist-pgsql">
174+
<database <!-- optional, as each of the following attributes are -->
175+
port="3000"
176+
user="toto"
177+
password="toto's secret"
178+
/>
179+
</extension>
180+
<!-- pa_pgsql.cma will be loaded automatically using findlib -->
172181

173182
<extension findlib-package="ocsigenserver.ext.eliom"/>
174183
<!-- Eliom's dependencies will be loaded automatically using findlib -->
@@ -182,7 +191,7 @@ Here is another example, for use as unprivileged user toto on port 8000:
182191
<site path="tuto">
183192
<eliom module="/usr/local/lib/ocsigenserver/tutoeliom.cmo" />
184193
<static dir="/home/toto/var/www/ocsigenserver/tutorial" />
185-
<!-- Module's path coul be relative but static dir must be absolute -->
194+
<!-- Module's path coul be relative but static dir must be absolute -->
186195
</site>
187196

188197
</host>

doc/manual-wiki/libraries.wiki

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
==Ocsipersist
77

8-
<<div class="wip"|Ocsipersist (2 implémentations)
8+
<<div class="wip"|Ocsipersist (3 implémentations)
99
Eliom allows to use more persistent data, using the module
1010
<<a_api project="ocsigenserver" | module Ocsipersist >> is needed in
1111
{{{ eliom.cma }}}, thus you need to dynlink it in the
1212
configuration file before {{{ Eliom }}}).
1313
There are currently two implementations of {{{ Ocsipersist }}}:
14-
{{{ ocsipersist-dbm.cma }}} (uses the DBM database) and
15-
{{{ ocsipersist-sqlite.cma }}} (uses the SQLite database,
16-
and depends on {{{ sqlite3.cma }}}).
14+
{{{ ocsipersist-dbm.cma }}} (uses the DBM database);
15+
{{{ ocsipersist-sqlite.cma }}} (uses the SQLite database
16+
and depends on {{{ sqlite3.cma }}});
17+
{{{ ocsipersist-pgsql.cma }}} (uses the PostgreSQL (version >= 9.5)
18+
database and depends on {{{ pa_pgsql.cma }}});
1719
>>
1820

1921
It is possible to customize the location of the database on the
@@ -31,3 +33,20 @@ name of the {{{ocsidbm}}} process you want to use:
3133
<ocsidbm name="_EXTRALIBDIR_/ocsidbm"/>
3234
</extension>
3335
}}}
36+
PostgreSQL has more options to specify how to connect to the database.
37+
Note that the ocsipersist-database under the specified name (default:
38+
"ocsipersist") needs to exist. To create it run {{{psql}}} and execute
39+
{{{CREATE TABLE ocsipersist;}}}.
40+
{{{
41+
<extension findlib-package="ocsigenserver.ext.ocsipersist-pgsql">
42+
<database <!-- optional, as each of the following attributes are -->
43+
host="localhost"
44+
port="3000"
45+
user="Aerobic Respirator"
46+
password="Guess what I need!"
47+
database="ocsipersist" <!-- this is the default value if not specified -->
48+
unix_domain_socket_dir="./udsd"
49+
size_conn_pool="16" <!-- this is the default value; number of DB connections -->
50+
/>
51+
</extension>
52+
}}}

opam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dev-repo: "https://github.com/ocsigen/ocsigenserver.git"
99
license: "LGPL-2.1 with OCaml linking exception"
1010
build: [
1111
["sh" "configure" "--prefix" "%{prefix}%" "--ocsigen-user" "%{user}%" "--ocsigen-group" "%{group}%" "--commandpipe" "%{lib}%/ocsigenserver/var/run/ocsigenserver_command" "--logdir" "%{lib}%/ocsigenserver/var/log/ocsigenserver" "--mandir" "%{man}%/man1" "--docdir" "%{lib}%/ocsigenserver/share/doc/ocsigenserver" "--commandpipe" "%{lib}%/ocsigenserver/var/run/ocsigenserver_command" "--staticpagesdir" "%{lib}%/ocsigenserver/var/www" "--datadir" "%{lib}%/ocsigenserver/var/lib/ocsigenserver" "--sysconfdir" "%{lib}%/ocsigenserver/etc/ocsigenserver"]
12-
[make]
12+
[make "-j%{jobs}%" ]
1313
]
1414
install: [make "install"]
1515
remove: [
@@ -30,6 +30,7 @@ depends: [
3030
"tyxml" {> "3.6.0"}
3131
"dbm"
3232
"sqlite3"
33+
"pgocaml" {>= "2.2"}
3334
"ipaddr" {>= "2.1"}
3435
"camlp4"
3536
]

src/Makefile.filelist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ ifeq "$(OCSIPERSISTSQLITE)" "YES"
8282
PLUGINS_IMPL += extensions/ocsipersist-sqlite.cma
8383
endif
8484

85+
ifeq "$(OCSIPERSISTPGSQL)" "YES"
86+
PLUGINS_IMPL += extensions/ocsipersist-pgsql.cma
87+
endif
88+
8589
ifeq "$(OCSIPERSISTDBM)" "YES"
8690
PLUGINS_IMPL += extensions/ocsipersist-dbm.cma
8791
PLUGINS_BIN += extensions/ocsipersist-dbm/ocsidbm

src/extensions/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ ifeq "$(NATDYNLINK)" "YES"
4646
opt:: ${FILES:.ml=.cmxs}
4747
endif
4848

49+
### PostgreSQL ###
50+
51+
ifeq "$(OCSIPERSISTPGSQL)" "YES"
52+
byte::
53+
$(MAKE) -C ocsipersist-pgsql byte
54+
opt::
55+
$(MAKE) -C ocsipersist-pgsql opt
56+
endif
4957
### SQLite ###
5058

5159
ifeq "$(OCSIPERSISTSQLITE)" "YES"
@@ -80,20 +88,24 @@ endif
8088
clean: clean.local
8189
${MAKE} -C ocsipersist-dbm clean
8290
${MAKE} -C ocsipersist-sqlite clean
91+
${MAKE} -C ocsipersist-pgsql clean
8392
clean.local:
8493
-rm -f *.cm* *.o *.a *.annot
8594
-rm -f ${PREDEP}
8695
distclean: clean.local
8796
-rm -f *~ \#* .\#*
8897
${MAKE} -C ocsipersist-dbm distclean
8998
${MAKE} -C ocsipersist-sqlite distclean
99+
${MAKE} -C ocsipersist-pgsql distclean
100+
-rm -f .depend
90101

91102
## Dependencies
92103

93104
depend: ${PREDEP}
94105
$(OCAMLDEP) ${LIBS} *.mli *.ml > .depend
95106
${MAKE} -C ocsipersist-dbm depend
96107
${MAKE} -C ocsipersist-sqlite depend
108+
${MAKE} -C ocsipersist-pgsql depend
97109

98110
FORCE:
99111
-include .depend

src/extensions/ocsipersist-dbm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ clean:
7171
-rm -f ocsidbm ocsidbm.opt
7272
distclean: clean
7373
-rm -f *~ \#* .\#*
74+
-rm -f .depend
7475

7576
## Dependencies
7677

src/extensions/ocsipersist-dbm/ocsipersist.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ let db_length store =
237237
(** Type of persistent data *)
238238
type 'a t = store * string
239239

240-
let open_store name : store = name
240+
let open_store name = Lwt.return name
241241

242242
let make_persistent_lazy_lwt ~store ~name ~default =
243243
let pvname = (store, name) in
@@ -270,7 +270,7 @@ let set pvname v =
270270
(** Type of persistent tables *)
271271
type 'value table = string
272272

273-
let open_table name = name
273+
let open_table name = Lwt.return name
274274

275275
let table_name n = Lwt.return n
276276

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
include ../../../Makefile.config
2+
3+
PACKAGE := tyxml.parser pgocaml.syntax lwt.syntax
4+
5+
LIBS := -I ../../baselib -I ../../http -I ../../server \
6+
${addprefix -package ,${PACKAGE}}
7+
OCAMLC := $(OCAMLFIND) ocamlc${BYTEDBG} ${THREAD}
8+
OCAMLOPT := $(OCAMLFIND) ocamlopt ${OPTDBG} ${THREAD}
9+
OCAMLDOC := $(OCAMLFIND) ocamldoc
10+
OCAMLDEP := $(OCAMLFIND) ocamldep
11+
12+
all: byte opt
13+
14+
###
15+
16+
byte: ocsipersist-pgsql.cma
17+
opt:: ocsipersist-pgsql.cmxa
18+
ifeq "$(NATDYNLINK)" "YES"
19+
opt:: ocsipersist-pgsql.cmxs
20+
endif
21+
22+
PREDEP := ocsipersist.mli
23+
24+
ocsipersist-pgsql.cma: ocsipersist.cmo
25+
$(OCAMLC) -a -o $@ $^
26+
cp ocsipersist.cmi ..
27+
cp $@ ..
28+
29+
ocsipersist-pgsql.cmxa: ocsipersist.cmx
30+
$(OCAMLOPT) -a -o $@ $^
31+
cp ocsipersist.cmi ..
32+
cp $@ ${patsubst %.cmxa,%.a,$@} ..
33+
34+
ocsipersist-pgsql.cmxs: ocsipersist-pgsql.cmxa
35+
$(OCAMLOPT) -shared -linkall -o $@ $^
36+
cp $@ ..
37+
38+
ocsipersist.mli:
39+
ln -s ../ocsipersist.mli .
40+
41+
##########
42+
43+
SYNTAX_FLAGS=-syntax camlp4o
44+
45+
%.cmi: %.mli
46+
$(OCAMLC) ${LIBS} -c $<
47+
%.cmo: %.ml
48+
$(OCAMLC) ${LIBS} ${SYNTAX_FLAGS} -c $<
49+
%.cmx: %.ml
50+
$(OCAMLOPT) ${LIBS} ${SYNTAX_FLAGS} -c $<
51+
%.cmxs: %.cmxa
52+
$(OCAMLOPT) -shared -linkall -o $@ $<
53+
54+
## Clean up
55+
56+
clean:
57+
-rm -f *.cm[ioax] *.cmxa *.cmxs *.o *.a *.annot
58+
-rm -f ${PREDEP}
59+
distclean: clean
60+
-rm -f *~ \#* .\#*
61+
-rm -f .depend
62+
63+
## Dependencies
64+
65+
depend: ${PREDEP}
66+
$(OCAMLDEP) ${LIBS} *.mli *.ml > .depend
67+
68+
FORCE:
69+
-include .depend

0 commit comments

Comments
 (0)