Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Minimalistic syntax extension for type-safe, convenient execution of SQL statements.
OCaml
Tag: 0.2.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
META
Makefile
OMakefile
OMakeroot
README
_oasis
_tags
configure
example.ml
myocamlbuild.ml
pa_sql.ml
setup.ml
sqlexpr.mllib
sqlexpr_concurrency.ml
sqlexpr_sqlite.ml
sqlexpr_sqlite.mli
sqlexpr_syntax.mllib
t_sqlexpr_sqlite.ml

README

Minimalistic library and syntax extension for type-safe, convenient execution
of SQL statements. Currently compatible with Sqlite3.

Sqlexpr features:
* automated prepared statement caching, param binding, data extraction, error
  checking (including automatic stmt reset to avoid BUSY/LOCKED errors in
  subsequent queries), stmt finalization on db close, etc.
* HOFs like iter, fold, transaction
* support for different concurrency models: everything is functorized over a
  THREAD monad, so you can for instance do concurrent folds/iters with Lwt
* support for SQL stmt syntax checks and some extra semantic checking (column
  names, etc)

Sqlexpr is used as follows:

    module Sqlexpr = Sqlexpr_sqlite.Make(Sqlexpr_concurrency.Id)
    module S = Sqlexpr

    let () =
      let db = S.open_db "foo.db" in
      S.iter db
        (fun (n, p) -> Printf.printf "User %S, password %S\n" n p)
        sqlc"SELECT @s{login}, @s{password} FROM users";
      List.iter
        (fun (n, p) -> S.execute db sqlc"INSERT INTO users VALUES(%s, %s) n p)
        [
         "coder24", "badpass";
         "tokyo3", "12345"
        ]

See also example.ml.

Sqlexpr includes a syntax extension to build type-safe SQL
statements/expressions:


  sql"..."   denotes a SQL statement expression
  sqlc"..."  denotes a SQL statement/expression that is to be cached

  sql_check"sqlite" returns a tuple of functions to initialize, check the
                    validity of the SQL statements/expressions and
                    check against an auto-initialized temporary database.

  sqlinit"..." is equivalent to sql"...", but the statement will be added
               to the list of statements to be executed in the automatically
               generated initialization function

sql_check"sqlite" is used as follows:

  let auto_init_db, check_db, auto_check_db = sql_check"sqlite"

which creates 3 functions

  val auto_init_db : Sqlite3.db -> Format.formatter -> bool
  val check_db : Sqlite3.db -> Format.formatter -> bool
  val auto_check_db : Format.formatter -> bool

each of them returns [false] on error, and writes the error messages to the
provided formatter.

Something went wrong with that request. Please try again.