[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ORM working in the toplevel



I did a refresh of the SQL ORM type extension that Thomas and I wrote a few 
years ago, and it's pretty cool on the toplevel!  Once Thomas merges the pull 
request for the new versions on OPAM [3], you can do "opam install orm utop", 
and with this in your ~/.ocamlinit:

#use "topfind"
#camlp4o
#thread

Try this in "utop":

utop $ #require "orm.syntax";;
utop $ type t = { foo: int; bar: string } with orm;;
<snip scary types>
utop $ let db = t_init "test.db";;
val db : (t, [ `RW ]) Orm.Db.t = <abstr>
}âutop $ t_save db { foo=1; bar="one" };;
- : unit = ()
}âutop $ t_save db { foo=2; bar="two" };;
- : unit = ()
}âutop $ t_get db;;
- : Cache_t.elt list = [{foo = 1; bar = "one"}; {foo = 2; bar = "two"}]
}âutop $ t_get ~bar:(`Contains "t") db;;
- : Cache_t.elt list = []
}âutop $ t_get ~bar:(`Contains "two") db;;
- : Cache_t.elt list = []
}âutop $ t_get ~bar:(`Eq "two") db;;
- : Cache_t.elt list = [{foo = 2; bar = "two"}]
utop $ t_get ~foo:(`Ge 0) db;;
- : Cache_t.elt list = [{foo = 1; bar = "one"}; {foo = 2; bar = "two"}]
}âutop $ t_get ~foo:(`Ge 1) db;;
- : Cache_t.elt list = [{foo = 2; bar = "two"}]

I can see a few improvements to do, such as adding a signature generator [1] to 
make the types more succinct (i.e. Cache_t.elt shouldnt be exposed), and also 
new database backends (some NoSQL ones might be good, perhaps to Arakoon).

Also Thomas, I notice that the `Contains query isn't working as expected. Is it 
meant to be a substring operation? See its use above. 

[1] https://github.com/mirage/orm/issues/7
[2] https://github.com/mirage/orm/issues/6
[3] https://github.com/OCamlPro/opam-repository/pull/96


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.