Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7467ab4
add SQL backend for ocsipersist
Jul 4, 2016
349d333
added function skeletons for ocsipersist-sql
Jul 4, 2016
5c6b5a7
Enabled lwt PPX syntax for ocsipersist-sql
Jul 4, 2016
78e53a3
store = table = string; allow to specify database
Jul 4, 2016
4225b35
use higher-order function instead of primitive recursion
Jul 6, 2016
a69d404
added more config options for DB connection
Jul 6, 2016
72baade
copy connection-handling code from Eba_db
Jul 6, 2016
c1a73b6
syntax flags
Jul 6, 2016
54b5365
added SQL options to config file
Jul 6, 2016
a351630
syntax flags; tyxml
Jul 6, 2016
6d6fd23
fixed all the infrastructure problems
Jul 6, 2016
2e9b56c
reverted some accidental changes
Jul 6, 2016
4af5405
some first queries
Jul 7, 2016
2cf874d
cosmetics
Jul 7, 2016
c4d2c5f
some more functions
Jul 7, 2016
b2582bf
cosmetics
Jul 7, 2016
5e849f6
changed types of open_store and open_table into Lwt functions
Jul 7, 2016
0900a0e
some more functions
Jul 7, 2016
5f20a88
implemented the remaining functions
Jul 7, 2016
64eb81e
removed dependency from macaque
Jul 7, 2016
60cfbc7
cosmetics
Jul 7, 2016
45b335c
added ocsipersist-sql package description
Jul 7, 2016
8589560
added parallel build flag
Jul 7, 2016
3f36e93
fixed bug (I just can't stop in terms of lazy evaluation)
Jul 7, 2016
5fc5170
BLOB -> BYTEA
Jul 7, 2016
f539cac
some fixes and improvements
Jul 8, 2016
e879e10
removed remainder of old macaque dependency
Jul 8, 2016
5df8a67
corrected marshalling/unmarshalling
Jul 8, 2016
186425e
various fixes
Jul 8, 2016
0783bcb
rename ocsipersist-sql to ocsipersist-pgsql
Jul 8, 2016
f44f547
updated docs
Jul 8, 2016
3f5713e
Delete .depend file on distclean
Jul 8, 2016
8e5e467
string escape key names
Jul 8, 2016
022ac43
use as default database name "ocsipersist"
Jul 8, 2016
2c61c8a
don't use unnecessary transaction blocks
Jul 8, 2016
3235c59
use UPDATE for [set] instead of INSERT
Jul 11, 2016
dc9a242
Wiki documentation for ocsipersist-pgsql
Jul 11, 2016
23b1bf7
cache queries in a hash table
Jul 11, 2016
8064c11
make_persistent does not do a SELECT query anymore
Jul 11, 2016
9398874
fix replace_if_exists
Jul 11, 2016
1b593ca
add configuration parameter for connection pool size
Jul 11, 2016
b0f08ea
updated doc to latest changes
Jul 11, 2016
f33a396
refixed make_persistent
Jul 11, 2016
1823669
doc
Jul 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Libraries:
* tyxml (need version 3)
* ipaddr (need version >= 2.1)
* ocamlsqlite3 (tested with 2.0.2) OR
* pgocaml (tested with 2.3) OR
* dbm (tested with 1.0)


Expand Down
18 changes: 17 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set_defaults () {
enable_debug=1
enable_annot=1
with_sqlite=1
with_pgsql=1
with_camlzip=1
with_dbm=1
with_preempt=1
Expand Down Expand Up @@ -107,7 +108,7 @@ full_pwd=`pwd`

## Which options exist? eoptions for enable/disable, woptions for with/without:
eoptions="debug annot natdynlink"
woptions="sqlite dbm camlzip preempt"
woptions="pgsql sqlite dbm camlzip preempt"

print_options () {
for opt in $eoptions; do
Expand Down Expand Up @@ -184,6 +185,7 @@ usage: ./configure [ options ]
--enable-natdynlink, --disable-natdynlink Enable/disable nativecode dynamic linking

--with-sqlite, --without-sqlite Compile ocsipersist with SQLite for persistent storage
--with-pgsql, --without-pgsql Compile ocsipersist with PostgreSQL for persistent storage
--with-dbm, --without-dbm Compile ocsipersist with DBM for persistent storage
--with-camlzip, --without-camlzip Compile deflatemod extension, requires camlzip

Expand Down Expand Up @@ -424,6 +426,12 @@ check_library cryptokit "See: http://pauillac.inria.fr/~xleroy/software.html#cry

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

# Check PostgreSQL
case "$with_pgsql" in
1) if test_library pgocaml; then with_pgsql=1; else with_pgsql=0; fi;;
2) check_library pgocaml "https://github.com/darioteixeira/pgocaml";;
esac

# Check Sqlite3
case "$with_sqlite" in
1) if test_library sqlite3; then with_sqlite=1; else with_sqlite=0; fi;;
Expand Down Expand Up @@ -514,6 +522,11 @@ if [ $with_sqlite -gt 0 ] ; then
else
with_sqlite="NO"
fi
if [ $with_pgsql -gt 0 ] ; then
with_pgsql="YES"
else
with_pgsql="NO"
fi
if [ $with_camlzip -gt 0 ] ; then
with_camlzip="YES"
else
Expand Down Expand Up @@ -569,6 +582,9 @@ CAMLZIPNAME:=$zipname
# Do you want ocsipersist with sqlite? YES/NO
OCSIPERSISTSQLITE:=$with_sqlite

# Do you want ocsipersist with pgsql? YES/NO
OCSIPERSISTPGSQL:=$with_pgsql

# Do you want ocsipersist with dbm? YES/NO
OCSIPERSISTDBM:=$with_dbm

Expand Down
17 changes: 13 additions & 4 deletions doc/manual-wiki/config.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ Here is a simple example:
</ocsigen>
}}}

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

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

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

<extension findlib-package="ocsigenserver.ext.ocsipersist-sqlite"/>
<!-- sqlite3.cma will be loaded automatically using findlib -->
<extension findlib-package="ocsigenserver.ext.ocsipersist-pgsql">
<database <!-- optional, as each of the following attributes are -->
port="3000"
user="toto"
password="toto's secret"
/>
</extension>
<!-- pa_pgsql.cma will be loaded automatically using findlib -->

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

</host>
Expand Down
27 changes: 23 additions & 4 deletions doc/manual-wiki/libraries.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

==Ocsipersist

<<div class="wip"|Ocsipersist (2 implémentations)
<<div class="wip"|Ocsipersist (3 implémentations)
Eliom allows to use more persistent data, using the module
<<a_api project="ocsigenserver" | module Ocsipersist >> is needed in
{{{ eliom.cma }}}, thus you need to dynlink it in the
configuration file before {{{ Eliom }}}).
There are currently two implementations of {{{ Ocsipersist }}}:
{{{ ocsipersist-dbm.cma }}} (uses the DBM database) and
{{{ ocsipersist-sqlite.cma }}} (uses the SQLite database,
and depends on {{{ sqlite3.cma }}}).
{{{ ocsipersist-dbm.cma }}} (uses the DBM database);
{{{ ocsipersist-sqlite.cma }}} (uses the SQLite database
and depends on {{{ sqlite3.cma }}});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't be better to point to the opam package name ... ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

{{{ ocsipersist-pgsql.cma }}} (uses the PostgreSQL (version >= 9.5)
database and depends on {{{ pa_pgsql.cma }}});
>>

It is possible to customize the location of the database on the
Expand All @@ -31,3 +33,20 @@ name of the {{{ocsidbm}}} process you want to use:
<ocsidbm name="_EXTRALIBDIR_/ocsidbm"/>
</extension>
}}}
PostgreSQL has more options to specify how to connect to the database.
Note that the ocsipersist-database under the specified name (default:
"ocsipersist") needs to exist. To create it run {{{psql}}} and execute
{{{CREATE TABLE ocsipersist;}}}.
{{{
<extension findlib-package="ocsigenserver.ext.ocsipersist-pgsql">
<database <!-- optional, as each of the following attributes are -->
host="localhost"
port="3000"
user="Aerobic Respirator"
password="Guess what I need!"
database="ocsipersist" <!-- this is the default value if not specified -->
unix_domain_socket_dir="./udsd"
size_conn_pool="16" <!-- this is the default value; number of DB connections -->
/>
</extension>
}}}
3 changes: 2 additions & 1 deletion opam
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dev-repo: "https://github.com/ocsigen/ocsigenserver.git"
license: "LGPL-2.1 with OCaml linking exception"
build: [
["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"]
[make]
[make "-j%{jobs}%" ]
]
install: [make "install"]
remove: [
Expand All @@ -30,6 +30,7 @@ depends: [
"tyxml" {> "3.6.0"}
"dbm"
"sqlite3"
"pgocaml" {>= "2.2"}
"ipaddr" {>= "2.1"}
"camlp4"
]
Expand Down
4 changes: 4 additions & 0 deletions src/Makefile.filelist
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ ifeq "$(OCSIPERSISTSQLITE)" "YES"
PLUGINS_IMPL += extensions/ocsipersist-sqlite.cma
endif

ifeq "$(OCSIPERSISTPGSQL)" "YES"
PLUGINS_IMPL += extensions/ocsipersist-pgsql.cma
endif

ifeq "$(OCSIPERSISTDBM)" "YES"
PLUGINS_IMPL += extensions/ocsipersist-dbm.cma
PLUGINS_BIN += extensions/ocsipersist-dbm/ocsidbm
Expand Down
12 changes: 12 additions & 0 deletions src/extensions/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ ifeq "$(NATDYNLINK)" "YES"
opt:: ${FILES:.ml=.cmxs}
endif

### PostgreSQL ###

ifeq "$(OCSIPERSISTPGSQL)" "YES"
byte::
$(MAKE) -C ocsipersist-pgsql byte
opt::
$(MAKE) -C ocsipersist-pgsql opt
endif
### SQLite ###

ifeq "$(OCSIPERSISTSQLITE)" "YES"
Expand Down Expand Up @@ -80,20 +88,24 @@ endif
clean: clean.local
${MAKE} -C ocsipersist-dbm clean
${MAKE} -C ocsipersist-sqlite clean
${MAKE} -C ocsipersist-pgsql clean
clean.local:
-rm -f *.cm* *.o *.a *.annot
-rm -f ${PREDEP}
distclean: clean.local
-rm -f *~ \#* .\#*
${MAKE} -C ocsipersist-dbm distclean
${MAKE} -C ocsipersist-sqlite distclean
${MAKE} -C ocsipersist-pgsql distclean
-rm -f .depend

## Dependencies

depend: ${PREDEP}
$(OCAMLDEP) ${LIBS} *.mli *.ml > .depend
${MAKE} -C ocsipersist-dbm depend
${MAKE} -C ocsipersist-sqlite depend
${MAKE} -C ocsipersist-pgsql depend

FORCE:
-include .depend
1 change: 1 addition & 0 deletions src/extensions/ocsipersist-dbm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ clean:
-rm -f ocsidbm ocsidbm.opt
distclean: clean
-rm -f *~ \#* .\#*
-rm -f .depend

## Dependencies

Expand Down
4 changes: 2 additions & 2 deletions src/extensions/ocsipersist-dbm/ocsipersist.ml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ let db_length store =
(** Type of persistent data *)
type 'a t = store * string

let open_store name : store = name
let open_store name = Lwt.return name

let make_persistent_lazy_lwt ~store ~name ~default =
let pvname = (store, name) in
Expand Down Expand Up @@ -270,7 +270,7 @@ let set pvname v =
(** Type of persistent tables *)
type 'value table = string

let open_table name = name
let open_table name = Lwt.return name

let table_name n = Lwt.return n

Expand Down
69 changes: 69 additions & 0 deletions src/extensions/ocsipersist-pgsql/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
include ../../../Makefile.config

PACKAGE := tyxml.parser pgocaml.syntax lwt.syntax

LIBS := -I ../../baselib -I ../../http -I ../../server \
${addprefix -package ,${PACKAGE}}
OCAMLC := $(OCAMLFIND) ocamlc${BYTEDBG} ${THREAD}
OCAMLOPT := $(OCAMLFIND) ocamlopt ${OPTDBG} ${THREAD}
OCAMLDOC := $(OCAMLFIND) ocamldoc
OCAMLDEP := $(OCAMLFIND) ocamldep

all: byte opt

###

byte: ocsipersist-pgsql.cma
opt:: ocsipersist-pgsql.cmxa
ifeq "$(NATDYNLINK)" "YES"
opt:: ocsipersist-pgsql.cmxs
endif

PREDEP := ocsipersist.mli

ocsipersist-pgsql.cma: ocsipersist.cmo
$(OCAMLC) -a -o $@ $^
cp ocsipersist.cmi ..
cp $@ ..

ocsipersist-pgsql.cmxa: ocsipersist.cmx
$(OCAMLOPT) -a -o $@ $^
cp ocsipersist.cmi ..
cp $@ ${patsubst %.cmxa,%.a,$@} ..

ocsipersist-pgsql.cmxs: ocsipersist-pgsql.cmxa
$(OCAMLOPT) -shared -linkall -o $@ $^
cp $@ ..

ocsipersist.mli:
ln -s ../ocsipersist.mli .

##########

SYNTAX_FLAGS=-syntax camlp4o

%.cmi: %.mli
$(OCAMLC) ${LIBS} -c $<
%.cmo: %.ml
$(OCAMLC) ${LIBS} ${SYNTAX_FLAGS} -c $<
%.cmx: %.ml
$(OCAMLOPT) ${LIBS} ${SYNTAX_FLAGS} -c $<
%.cmxs: %.cmxa
$(OCAMLOPT) -shared -linkall -o $@ $<

## Clean up

clean:
-rm -f *.cm[ioax] *.cmxa *.cmxs *.o *.a *.annot
-rm -f ${PREDEP}
distclean: clean
-rm -f *~ \#* .\#*
-rm -f .depend

## Dependencies

depend: ${PREDEP}
$(OCAMLDEP) ${LIBS} *.mli *.ml > .depend

FORCE:
-include .depend
Loading