This is the datafly Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 05:54:41 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
datafly
Lightweight database library.
Eitaro Fukamachi
BSD 3-Clause
# datafly
[![Build Status](https://travis-ci.org/fukamachi/datafly.svg?branch=master)](https://travis-ci.org/fukamachi/datafly)
Datafly is a lightweight database library for Common Lisp.
## Quickstart
Datafly provides 3 functions which wrap [CL-DBI](https://github.com/fukamachi/cl-dbi) — ‘retrieve-one‘, ‘retrieve-all‘ and ‘execute‘.
They take a [SxQL](https://github.com/fukamachi/sxql) statement.
“‘common-lisp
(use-package :sxql)
(connect-toplevel :sqlite3 :database-name #P"myapp.db")
(retrieve-one
(select :*
(from :user)
(where (:= :name "nitro_idiot"))))
;=> (:ID 1 :NAME "nitro_idiot" :EMAIL "nitro_idiot@example.com" :REGISTERED-AT "2014-04-14T19:20:13")
(retrieve-all
(select :*
(from :user)))
;=> ((:ID 1 :NAME "nitro_idiot" :EMAIL "nitro_idiot@example.com" :REGISTERED-AT "2014-04-14T19:20:13")
; (:ID 2 :NAME "m2ym" :EMAIL "m2ym@example.com" :REGISTERED-AT "2014-04-15T01:03:42"))
(execute
(insert-into :tweet
(set= :id 1
:user_id 1
:body "Hi."
:created_at (princ-to-string *now*))))
“‘
If you specify ‘:as‘ option with a class name to retrieval functions, they create instances of the class for each rows.
“‘common-lisp
(defstruct user
id
name
email
registered-at)
(retrieve-one
(select :*
(from :user)
(where (:= :name "nitro_idiot")))
:as ’user)
;=> #S(USER :ID 1 :NAME "nitro_idiot" :EMAIL "nitro_idiot@example.com" :REGISTERED-AT "2014-04-14T19:20:13")
(retrieve-all
(select :*
(from :user))
:as ’user)
;=> (#S(USER :ID 1 :NAME "nitro_idiot" :EMAIL "nitro_idiot@example.com" :REGISTERED-AT "2014-04-14T19:20:13")
; #S(USER :ID 2 :NAME "m2ym" :EMAIL "m2ym@example.com" :REGISTERED-AT "2014-04-15T01:03:42"))
“‘
The structure doesn’t require having slots same as an existing table’s in a database. It is acceptable even if the names are different. This might be convenient when you’d like to treat a JOINed table result as a structure object.
## Model Definitions
Datafly provides a macro ‘defmodel‘ which defines a flavored structure class.
“‘common-lisp
(defmodel (user (:inflate registered-at #’datetime-to-timestamp))
id
name
email
registered-at)
;; Same as the above.
(syntax:use-syntax :annot)
@model
(defstruct (user (:inflate registered-at #’datetime-to-timestamp))
id
name
email
registered-at)
“‘
‘(:inflate <columns> <inflation-function>)‘ options mean ‘inflation-function‘ will be applied to each ‘<columns>‘ when creating an instance.
“‘common-lisp
(defvar *user*
(retrieve-one
(select :*
(from :user)
(where (:= :name "nitro_idiot")))
:as ’user))
;; Returns a local-time:timestamp.
(user-registered-at *user*)
;=> @2014-04-15T04:20:13.000000+09:00
“‘
‘defmodel‘ also allows ‘:has-a‘ and ‘:has-many‘ options.
“‘common-lisp
(use-package :sxql)
(defmodel (user (:inflate registered-at #’datetime-to-timestamp)
(:has-a config (where (:= :user_id id)))
(:has-many (tweets tweet)
(select :*
(from :tweet)
(where (:= :user_id id))
(order-by (:desc :created_at)))))
id
name
email
registered-at)
(defvar *user*
(retrieve-one
(select :*
(from :user)
(where (:= :name "nitro_idiot")))
:as ’user))
(user-config *user*)
;=> #S(CONFIG :ID 4 :USER-ID 1 :TIMEZONE "JST" :COUNTRY "jp" :LANGUAGE "ja")
(user-tweets *user*)
;=> (#S(TWEET :ID 2 :USER-ID 1 :BODY "Is it working?" :CREATED-AT @2014-04-16T11:02:31.000000+09:00)
; #S(TWEET :ID 1 :USER-ID 1 :BODY "Hi." :CREATED-AT @2014-04-15T18:58:20.000000+09:00))
“‘
## Provided inflation functions
* ‘tinyint-to-boolean‘
* ‘datetime-to-timestamp‘
* ‘unixtime-to-timestamp‘
* ‘string-to-keyword‘
* ‘octet-vector-to-string‘
## Tips: Getting Association List or Hash Table for each rows
‘retrieve-one‘ and ‘retrieve-all‘ return row(s) as a property list or a list of property lists by default.
If you’d like they were other types, for example "Association List" or "Hash Table", you can do it by passing ‘:as‘ parameter.
“‘common-lisp
(retrieve-one
(select :*
(from :user)
(where (:= :name "nitro_idiot")))
:as ’trivial-types:association-list)
;=> ((:ID . 1) (:NAME . "nitro_idiot") (:EMAIL . "nitro_idiot@example.com") (:REGISTERED-AT . "2014-04-14T19:20:13"))
(retrieve-one
(select :*
(from :user)
(where (:= :name "nitro_idiot")))
:as ’hash-table)
;=> #<HASH-TABLE :TEST EQL :COUNT 4 {1007AE3CD3}>
“‘
If no ‘:as‘ parameter is specified, ‘*default-row-type*‘ will be used.
“‘common-lisp
(let ((*default-row-type* ’hash-table))
(retrieve-all
(select :*
(from :user))))
;=> (#<HASH-TABLE :TEST EQL :COUNT 4 {100815FA03}> #<HASH-TABLE :TEST EQL :COUNT 4 {100815FE43}>)
“‘
## See Also
* [SxQL](https://github.com/fukamachi/sxql)
* [CL-DBI](https://github.com/fukamachi/cl-dbi)
* [cl-annot](https://github.com/arielnetworks/cl-annot), [CL-SYNTAX](https://github.com/m2ym/cl-syntax)
* [function-cache](https://github.com/AccelerationNet/function-cache)
## Author
* Eitaro Fukamachi (e.arrows@gmail.com)
## Copyright
Copyright (c) 2014 Eitaro Fukamachi (e.arrows@gmail.com)
# License
Licensed under the BSD 3-Clause License.
0.1
iterate
(system).
optima
(system).
trivial-types
(system).
closer-mop
(system).
named-readtables
(system).
sxql
(system).
dbi
(system).
alexandria
(system).
babel
(system).
local-time
(system).
function-cache
(system).
jonathan
(system).
kebab
(system).
log4cl
(system).
src
(module).
Modules are listed depth-first from the system components tree.
datafly/src
datafly
(system).
datafly.lisp
(file).
model.lisp
(file).
db.lisp
(file).
cache.lisp
(file).
logger.lisp
(file).
inflate.lisp
(file).
json.lisp
(file).
syntax.lisp
(file).
util.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
datafly/datafly.asd
datafly/src/datafly.lisp
datafly/src/model.lisp
datafly/src/db.lisp
datafly/src/cache.lisp
datafly/src/logger.lisp
datafly/src/inflate.lisp
datafly/src/json.lisp
datafly/src/syntax.lisp
datafly/src/util.lisp
datafly/src/datafly.lisp
model.lisp
(file).
db.lisp
(file).
cache.lisp
(file).
logger.lisp
(file).
inflate.lisp
(file).
json.lisp
(file).
syntax.lisp
(file).
src
(module).
datafly/src/model.lisp
db.lisp
(file).
cache.lisp
(file).
syntax.lisp
(file).
util.lisp
(file).
src
(module).
copy-model
(function).
defmodel
(macro).
model
(macro).
object-to-plist
(function).
datafly/src/db.lisp
logger.lisp
(file).
syntax.lisp
(file).
src
(module).
*connection*
(special variable).
*default-row-type*
(special variable).
connect-cached
(function).
connect-toplevel
(function).
database-type
(function).
disconnect-toplevel
(function).
execute
(function).
retrieve-all
(function).
retrieve-all-values
(function).
retrieve-one
(function).
retrieve-one-value
(function).
*connections*
(special variable).
connection-quote-character
(function).
convert-column-name
(function).
convert-column-value
(function).
convert-row
(function).
execute-with-connection
(function).
get-prev-stack
(function).
datafly/src/cache.lisp
syntax.lisp
(file).
src
(module).
clear-model-caches
(function).
clear-object-caches
(function).
defcached-accessor
(macro).
*model-accessors*
(special variable).
accessor-cache
(function).
datafly/src/logger.lisp
syntax.lisp
(file).
src
(module).
*sql-logger*
(special variable).
*trace-sql*
(special variable).
*sql-logger-pattern*
(special variable).
datafly/src/inflate.lisp
db.lisp
(file).
syntax.lisp
(file).
src
(module).
datetime-to-timestamp
(function).
octet-vector-to-string
(function).
string-to-keyword
(function).
tinyint-to-boolean
(function).
unixtime-to-timestamp
(function).
datafly/src/json.lisp
syntax.lisp
(file).
src
(module).
convert-object
(generic function).
encode-json
(generic function).
association-list-p
(function).
convert-for-json
(function).
object-to-plist
(function).
datafly/src/syntax.lisp
src
(module).
enable-syntax
(macro).
datafly/src/util.lisp
src
(module).
partition
(function).
partition-if
(function).
Packages are listed by definition order.
datafly.logger
datafly.db
datafly.cache
datafly
datafly.util
datafly.model
datafly.syntax
datafly.json
datafly.inflate
datafly.logger
common-lisp
.
datafly.syntax
.
*sql-logger*
(special variable).
*trace-sql*
(special variable).
*sql-logger-pattern*
(special variable).
datafly.db
common-lisp
.
datafly.syntax
.
iterate
.
sxql
.
*connection*
(special variable).
*default-row-type*
(special variable).
connect-cached
(function).
connect-toplevel
(function).
database-type
(function).
disconnect-toplevel
(function).
execute
(function).
retrieve-all
(function).
retrieve-all-values
(function).
retrieve-one
(function).
retrieve-one-value
(function).
*connections*
(special variable).
connection-quote-character
(function).
convert-column-name
(function).
convert-column-value
(function).
convert-row
(function).
execute-with-connection
(function).
get-prev-stack
(function).
datafly.cache
common-lisp
.
datafly.syntax
.
function-cache
.
iterate
.
clear-model-caches
(function).
clear-object-caches
(function).
defcached-accessor
(macro).
*model-accessors*
(special variable).
accessor-cache
(function).
datafly.util
common-lisp
.
datafly.syntax
.
partition
(function).
partition-if
(function).
datafly.model
common-lisp
.
datafly.syntax
.
iterate
.
optima
.
sxql
.
copy-model
(function).
defmodel
(macro).
model
(macro).
object-to-plist
(function).
datafly.syntax
common-lisp
.
enable-syntax
(macro).
datafly.json
common-lisp
.
datafly.syntax
.
iterate
.
convert-object
(generic function).
encode-json
(generic function).
association-list-p
(function).
convert-for-json
(function).
object-to-plist
(function).
datafly.inflate
common-lisp
.
datafly.syntax
.
datetime-to-timestamp
(function).
octet-vector-to-string
(function).
string-to-keyword
(function).
tinyint-to-boolean
(function).
unixtime-to-timestamp
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Jump to: | A C D E F G M O P R S T U |
---|
Jump to: | A C D E F G M O P R S T U |
---|
Jump to: | *
S |
---|
Jump to: | *
S |
---|
Jump to: | C D F I J L M P S U |
---|
Jump to: | C D F I J L M P S U |
---|