mfp / ocaml-sqlexpr

Minimalistic syntax extension for type-safe, convenient execution of SQL statements.
Other
86 stars 17 forks source link

Not sure how to use the syntax extension #8

Closed foretspaisibles closed 8 years ago

foretspaisibles commented 8 years ago

I tried to compile the code example, which failed:

% ocamlfind ocamlc -c -package "sqlexpr sqlexpr.syntax" -predicates "camlp4 preprocessor" -thread -syntax pa_sql -o example_1.cmo example_1.ml
File "example_1.ml", line 1, characters 0-6:
Parse error: entry [implem] is empty
File "example_1.ml", line 1:
Error: Error while running external preprocessor
Command line: camlp4 '-I' '/opt/opam/4.02.3/lib/ocaml/camlp4' '-I' '/opt/opam/4.02.3/lib/estring' '-I' '/opt/opam/4.02.3/lib/sqlexpr' 'estring.cma' 'sqlexpr_syntax.cma'  'example_1.ml' > /var/folders/lr/nbdc60md2418tr35tbbd2lc80000gn/T/ocamlpp435e0e

How to fix the compilation command to compile the example snippet. It is

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

let insert_user_stmt =
    sqlc"INSERT INTO users(login, password, email) VALUES(%s, %s, %s?)"

let insert_user db ~login ?email ~password =
  S.execute db insert_user_stmt login password email

(* insert user and return ID; we use partial application here *)
let new_user_id db = S.insert db insert_user_stmt

let get_password db =
  S.select_one db sqlc"SELECT @s{password} FROM users WHERE login = %s"

let get_email db =
  S.select_one db sqlc"SELECT @s?{email} FROM users WHERE login = %s"

let iter_users db f =
  S.iter db f sqlc"SELECT @L{id}, @s{login}, @s{password}, @s?{email}
                     FROM users"
j0sh commented 8 years ago

That command line looks strange. This works for me:

ocamlfind ocamlc -package sqlexpr,sqlexpr.syntax -syntax camlp4o -linkpkg -thread example.ml
mfp commented 8 years ago

I just triple-checked :) that the example compiles with j0sh's command line (which is what one would use normally), so AFAICS there's no other problem here.