ORM
is a database-agnostic ORM for Carp.
Installation
Load a backend from the package. The SQLite backend pulls in the
ORM core and the sqlite3 package transitively:
(load "git@github.com:carpentry-org/orm@0.1.0" "backends/sqlite3.carp")
Usage
(load "git@github.com:carpentry-org/orm@0.1.0" "backends/sqlite3.carp")
(deftype Item [id Int text String done Bool])
(derive-model Item SQLiteBackend [id Int])
(defn main []
(let-do [db (Result.unsafe-from-success (SQLite3.open "app.db"))]
(Item.create-table &db)
(ignore (Item.insert &db &(Item.init 0 @"buy milk" false)))
(println* &(Item.find-all &db))
(SQLite3.close db)))
derive-model reads the deftype's fields with members and emits CRUD
functions in the type's module. The SQL dialect and row marshalling are
delegated to a backend module, so the same model definition works against
any database with a backend.