~subsetpark/doozer

doozer/project.janet -rw-r--r-- 2.0 KiB
4a8e0e3e — Zach Smith update docs 1 year, 13 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(declare-project
  :name "doozer"
  :description "composable SQL queries"
  :authors ["Z. D. Smith <zd@zdmith.com>"]
  :license "BSD3"
  :url "https://git.sr.ht/~subsetpark/doozer"
  :repo "https://git.sr.ht/~subsetpark/doozer"
  :doc
  ````
  # doozer: composable SQL queries for Janet

  *This software is currently Alpha quality and in heavy development!*

  Doozer is a library, inspired by Elixir's [Ecto][ecto], which provides the
  ability to write SQL queries using a convenient, idiomatic Janet DSL, which
  are highly composable---that is, doozer produces data structures which should
  be easy to combine in order to create new SQL queries.

  [ecto]: https://hexdocs.pm/ecto/Ecto.html

  Currently supported features:
  - SELECT
  - WHERE
  - JOIN
  - Subqueries
  - SQL function calls
  - Raw SQL fragments

  Currently supported backends:

  - SQLite
  - PostgresQL

  # Usage

  The basic flow of a doozer query is:

  1. Construct a query out of one or more calls to the `from` macro
  2. Render that into concrete SQL using the function `to-sql`
  3. Evaluate the SQL using the library associated with a specific database

  For instance, here's an entire session using SQLite:

  ```
  (use doozer)
  (import sqlite3)

  (def db (sqlite3/open "chinook.db"))

  (def q (from "artists" a :select [name]))
  (def sql-and-params (to-sql q))

  (sqlite3/eval ;sql-and-params)
  ```

  ### Config

  Doozer has multiple backends available, which will output SQL compatible with
  a specific SQL database.

  To configure doozer, set the dynamic variable `:doozer/sql-backend` to point
  to the correct value.

  Available backends:

  - `doozer/backends/sqlite/backend`
  - `doozer/backends/postgres/backend`

  Backend modules also expose a `config!` convenience function which will set
  the variable for you. For instance:

  ```
  (import doozer/backends/sqlite)
  (sqlite/config!)
  ```

  Doozer queries are agnostic of any backend; however, `doozer/to-sql` will
  error if no backend is set.
  ````)

(declare-source
  :source ["doozer.janet" "doozer"])