Skip to content

Commit dc2a28c

Browse files
committed
docs(getting-started): streamline onboarding guides
1 parent 35288ba commit dc2a28c

File tree

2 files changed

+100
-213
lines changed

2 files changed

+100
-213
lines changed

README.md

Lines changed: 10 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Bisql
22

3+
[![Clojars Project](https://img.shields.io/clojars/v/io.github.hatappo/bisql.svg)](https://clojars.org/io.github.hatappo/bisql)
4+
[![Docs](https://img.shields.io/badge/docs-pages-cdc0a6)](https://hatappo.github.io/bisql/)
5+
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/hatappo/bisql)
6+
37
<p align="center">
48
<img src="docs/img/bicycle.svg" alt="Bisql bicycle logo" width="96" height="96" />
59
</p>
@@ -16,225 +20,23 @@ No data mapper
1620
No hidden SQL
1721
No boilerplate SQL
1822

19-
[![Clojars Project](https://img.shields.io/clojars/v/io.github.hatappo/bisql.svg)](https://clojars.org/io.github.hatappo/bisql)
20-
[![Docs](https://img.shields.io/badge/docs-pages-cdc0a6)](https://hatappo.github.io/bisql/)
21-
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/hatappo/bisql)
22-
2323
> [!NOTE]
2424
> This project is still early and the API may change.
2525
> Support for databases beyond PostgreSQL and Malli integration are both planned.
2626
2727
## Installation
2828

29-
Add it to `deps.edn`:
30-
31-
```clojure
32-
{:deps {io.github.hatappo/bisql {:mvn/version "0.2.0"}}}
33-
```
34-
35-
If you want a shorter CLI entrypoint, you can also add an alias:
29+
The full Installation guide lives here:
3630

37-
```clojure
38-
{:aliases
39-
{:bisql {:main-opts ["-m" "bisql.cli"]}}}
40-
```
41-
42-
Then commands such as these become available:
43-
44-
```sh
45-
clojure -M:bisql gen-config
46-
clojure -M:bisql gen-crud
47-
clojure -M:bisql gen-declarations
48-
```
49-
50-
If you prefer `bb`, you can also add tasks like:
51-
52-
```clojure
53-
{:tasks
54-
{:gen-config (apply clojure "-M:bisql" "gen-config" *command-line-args*)
55-
:gen-crud (apply clojure "-M:bisql" "gen-crud" *command-line-args*)
56-
:gen-declarations (apply clojure "-M:bisql" "gen-declarations" *command-line-args*)}}
57-
```
58-
59-
When passing CLI flags through `bb`, use `--` as a separator. For example:
60-
61-
```sh
62-
bb gen-declarations -- --include-sql-template --suppress-unused-public-var
63-
```
31+
- [docs/installation.md](docs/installation.md)
32+
- [https://hatappo.github.io/bisql/docs/installation/](https://hatappo.github.io/bisql/docs/installation/)
6433

6534
## Getting Started
6635

67-
### 1. Create a Minimal Table
68-
69-
Start with a simple table:
70-
71-
```sql
72-
CREATE TABLE users (
73-
id BIGSERIAL PRIMARY KEY,
74-
email TEXT NOT NULL UNIQUE,
75-
status TEXT NOT NULL
76-
);
77-
78-
CREATE TABLE orders (
79-
id BIGSERIAL PRIMARY KEY,
80-
user_id BIGINT NOT NULL,
81-
state TEXT NOT NULL,
82-
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
83-
);
36+
The full Getting Started guide lives here:
8437

85-
CREATE INDEX orders_state_created_at_idx
86-
ON orders (state, created_at);
87-
```
88-
89-
### 2. Write One Real SQL Query
90-
91-
Place a SQL template under a classpath `sql/...` directory.
92-
93-
For example:
94-
95-
- `src/sql/postgresql/public/users/find-active.sql`
96-
- `src/sql.clj`
97-
98-
```sql
99-
SELECT *
100-
FROM users
101-
WHERE status = /*$status*/'active'
102-
ORDER BY id
103-
LIMIT /*$limit*/100
104-
```
105-
106-
This template is still valid SQL: you can run it directly with the embedded literals, and bisql replaces those literals with bind parameters at runtime.
107-
108-
```clj
109-
(ns sql
110-
(:require [bisql.core :as bisql]))
111-
112-
(bisql/defquery)
113-
```
114-
115-
Then use the generated query function:
116-
117-
```clj
118-
(ns app.user-service
119-
(:require [next.jdbc :as jdbc]
120-
[sql.postgresql.public.users.core :as users]))
121-
122-
(def datasource
123-
(jdbc/get-datasource {:dbtype "postgresql"
124-
:host "localhost"
125-
:port 5432
126-
:dbname "bisql_dev"
127-
:user "bisql"
128-
:password "bisql"}))
129-
130-
(users/find-active datasource {:status "active"
131-
:limit 20})
132-
```
133-
134-
`bisql.core/defquery` uses the current namespace only to find SQL files.
135-
Each discovered SQL file defines executable query functions in the namespace derived from its file path, so the same SQL file always maps to the same namespace.
136-
By default, query execution uses the `:next-jdbc` adapter.
137-
138-
### 3. Generate Typical Index-Friendly Queries
139-
140-
Continuing from the previous example, you can generate a config template (`bisql.edn`) and modify it if needed:
141-
142-
```sh
143-
clojure -M -m bisql.cli gen-config
144-
```
145-
146-
Then generate the CRUD SQL:
147-
148-
```sh
149-
clojure -M -m bisql.cli gen-crud
150-
```
151-
152-
Depending on the tables present in the target database, this writes files such as:
153-
154-
- `src/sql/postgresql/public/users/crud.sql`
155-
- `src/sql/postgresql/public/orders/crud.sql`
156-
157-
Generated CRUD SQL includes templates such as `insert`, `insert-many`, `get-by-*`,
158-
`upsert-by-*`, `count`, `count-by-*`, `count-by-*-starting-with`, `update-by-*`,
159-
`delete-by-*`, `list`, `list-by-*`, and `list-by-*-starting-with`.
160-
161-
These generated queries are meant to cover the typical index-friendly SQL patterns
162-
you would usually write by hand. In practice, that often means you do not need to
163-
write much custom SQL at all. When you do need a custom query, the generated SQL
164-
templates are also a convenient base to copy and adapt.
165-
166-
For the sample tables above, this typically includes:
167-
168-
- `users.crud/insert`
169-
- `users.crud/insert-many`
170-
- `users.crud/upsert-by-id`
171-
- `users.crud/upsert-by-email`
172-
- `users.crud/get-by-id`
173-
- `users.crud/get-by-email`
174-
- `users.crud/count`
175-
- `users.crud/count-by-status`
176-
- `users.crud/count-by-status-starting-with`
177-
- `users.crud/list-by-email-starting-with`
178-
- `users.crud/update-by-id`
179-
- `users.crud/update-by-email`
180-
- `users.crud/delete-by-id`
181-
- `users.crud/delete-by-email`
182-
- `orders.crud/insert`
183-
- `orders.crud/insert-many`
184-
- `orders.crud/upsert-by-id`
185-
- `orders.crud/count`
186-
- `orders.crud/count-by-state`
187-
- `orders.crud/count-by-order-number-starting-with`
188-
- `orders.crud/count-by-state-and-created-at`
189-
- `orders.crud/list`
190-
- `orders.crud/get-by-id`
191-
- `orders.crud/update-by-id`
192-
- `orders.crud/delete-by-id`
193-
- `orders.crud/list-by-order-number-starting-with`
194-
- `orders.crud/list-by-state`
195-
- `orders.crud/list-by-state-and-created-at`
196-
197-
Then execute one of the generated functions:
198-
199-
```clj
200-
(ns app.order-service
201-
(:require [next.jdbc :as jdbc]
202-
[sql]
203-
[sql.postgresql.public.orders.crud :as orders]))
204-
205-
(def datasource
206-
(jdbc/get-datasource {:dbtype "postgresql"
207-
:host "localhost"
208-
:port 5432
209-
:dbname "bisql_dev"
210-
:user "bisql"
211-
:password "bisql"}))
212-
213-
(orders/list datasource {:limit 20
214-
:offset 0})
215-
```
216-
217-
SQL templates are resolved from the classpath under the logical `sql` base path.
218-
That means they can live under `src/sql/`, `resources/sql/`, or any other classpath root
219-
that exposes `sql/...`.
220-
221-
The same options can also be passed through environment variables such as
222-
`BISQL_HOST`, `BISQL_PORT`, `BISQL_DBNAME`, `BISQL_USER`, `BISQL_PASSWORD`,
223-
`BISQL_SCHEMA`, `BISQL_BASE_DIR`, `BISQL_DBTYPE`, and `BISQL_CONFIG`.
224-
225-
The precedence order is CLI options > environment variables > config file > defaults.
226-
227-
`gen-declarations` is an optional helper for projects that prefer explicit namespace
228-
files. It generates navigation-oriented `declare` forms with docstrings derived
229-
from the SQL templates, so IDEs and the REPL can jump to the intended namespace
230-
and query source without letting a shallow `(defquery)` populate undeclared
231-
namespaces. By default those docstrings include the project-relative SQL file path
232-
and line number; pass `--include-sql-template` if you also want the SQL template
233-
body included.
234-
235-
For more detail on the 2-way SQL syntax and rendering behavior, see:
236-
237-
- [docs/rendering-examples.md](docs/rendering-examples.md)
38+
- [docs/getting-started.md](docs/getting-started.md)
39+
- [https://hatappo.github.io/bisql/docs/getting-started/](https://hatappo.github.io/bisql/docs/getting-started/)
23840

23941
## Development
24042

docs/getting-started.md

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ CREATE INDEX orders_state_created_at_idx
2222

2323
## 2. Write One SQL Template
2424

25-
Place a SQL template under a classpath `sql/...` directory:
25+
Place a SQL template under a classpath `sql/...` directory.
26+
27+
For example:
2628

2729
```text
2830
src/sql/postgresql/public/users/find-active.sql
@@ -68,9 +70,14 @@ Then call the generated function:
6870
:limit 20})
6971
```
7072

73+
`bisql.core/defquery` uses the current namespace only to find SQL files.
74+
Each discovered SQL file defines executable query functions in the namespace derived
75+
from its file path, so the same SQL file always maps to the same namespace.
76+
By default, query execution uses the `:next-jdbc` adapter.
77+
7178
## 4. Generate CRUD SQL
7279

73-
Generate a config template:
80+
Continuing from the previous example, you can generate a config template (`bisql.edn`) and modify it if needed:
7481

7582
```sh
7683
clojure -M -m bisql.cli gen-config
@@ -101,16 +108,94 @@ Generated SQL typically includes:
101108
- `delete-by-*`
102109
- `upsert-by-*`
103110

111+
These generated queries are meant to cover the typical index-friendly SQL patterns
112+
you would usually write by hand. In practice, that often means you do not need to
113+
write much custom SQL at all. When you do need a custom query, the generated SQL
114+
templates are also a convenient base to copy and adapt.
115+
116+
For the sample tables above, this typically includes:
117+
118+
- `users.crud/insert`
119+
- `users.crud/insert-many`
120+
- `users.crud/upsert-by-id`
121+
- `users.crud/upsert-by-email`
122+
- `users.crud/get-by-id`
123+
- `users.crud/get-by-email`
124+
- `users.crud/count`
125+
- `users.crud/count-by-status`
126+
- `users.crud/count-by-status-starting-with`
127+
- `users.crud/list-by-email-starting-with`
128+
- `users.crud/update-by-id`
129+
- `users.crud/update-by-email`
130+
- `users.crud/delete-by-id`
131+
- `users.crud/delete-by-email`
132+
- `orders.crud/insert`
133+
- `orders.crud/insert-many`
134+
- `orders.crud/upsert-by-id`
135+
- `orders.crud/count`
136+
- `orders.crud/count-by-state`
137+
- `orders.crud/count-by-order-number-starting-with`
138+
- `orders.crud/count-by-state-and-created-at`
139+
- `orders.crud/list`
140+
- `orders.crud/get-by-id`
141+
- `orders.crud/update-by-id`
142+
- `orders.crud/delete-by-id`
143+
- `orders.crud/list-by-order-number-starting-with`
144+
- `orders.crud/list-by-state`
145+
- `orders.crud/list-by-state-and-created-at`
146+
147+
Then execute one of the generated functions:
148+
149+
```clojure
150+
(ns app.order-service
151+
(:require [next.jdbc :as jdbc]
152+
[sql]
153+
[sql.postgresql.public.orders.crud :as orders]))
154+
155+
(def datasource
156+
(jdbc/get-datasource
157+
{:dbtype "postgresql"
158+
:host "localhost"
159+
:port 5432
160+
:dbname "bisql_dev"
161+
:user "bisql"
162+
:password "bisql"}))
163+
164+
(orders/list datasource {:limit 20
165+
:offset 0})
166+
```
167+
168+
SQL templates are resolved from the classpath under the logical `sql` base path.
169+
That means they can live under `src/sql/`, `resources/sql/`, or any other classpath root
170+
that exposes `sql/...`.
171+
172+
The same options can also be passed through environment variables such as
173+
`BISQL_HOST`, `BISQL_PORT`, `BISQL_DBNAME`, `BISQL_USER`, `BISQL_PASSWORD`,
174+
`BISQL_SCHEMA`, `BISQL_BASE_DIR`, `BISQL_DBTYPE`, and `BISQL_CONFIG`.
175+
176+
The precedence order is CLI options > environment variables > config file > defaults.
177+
178+
`gen-declarations` is an optional helper for projects that prefer explicit namespace
179+
files. It generates navigation-oriented `declare` forms with docstrings derived
180+
from the SQL templates, so IDEs and the REPL can jump to the intended namespace
181+
and query source without letting a shallow `(defquery)` populate undeclared
182+
namespaces. By default those docstrings include the project-relative SQL file path
183+
and line number; pass `--include-sql-template` if you also want the SQL template
184+
body included.
185+
104186
See also:
105187

106188
- [Rendering](rendering.md)
107189
- [CRUD Generation](crud-generation.md)
190+
- [Rendering Examples](rendering-examples.md)
191+
192+
## 5. Wrap up
108193

109-
## 5. Developer Workflow with Bisql
194+
The developer workflow with Bisql is straightforward:
110195

111-
1. Run `clojure -M:bisql gen-crud` to generate the routine CRUD SQL you would otherwise write by hand.
196+
1. Add `defquery` to your application code once, so Bisql can turn SQL files, including generated ones, into ordinary Clojure functions.
112197

113-
2. Add `defquery` to your application code once, so Bisql can turn SQL files, including generated ones, into ordinary Clojure functions.
198+
2. Run `clojure -M:bisql gen-crud` to generate the routine CRUD SQL you would otherwise write by hand, and add hand-written SQL where you need more complex queries.
114199

115200
3. If needed, run `clojure -M:bisql gen-declarations` to generate matching `declare` forms for those functions.
116201

0 commit comments

Comments
 (0)