Updates the docs so that the example work straight away
& Updates gendocs.carp so it behaved incorectly on latest carp
This commit is contained in:
@@ -37,18 +37,27 @@ to wrap everything, but it tries to be useful.</p>
|
|||||||
<h2>Usage</h2>
|
<h2>Usage</h2>
|
||||||
<p>The module <code>SQLite3</code> provides facilities for opening, closing, and querying
|
<p>The module <code>SQLite3</code> provides facilities for opening, closing, and querying
|
||||||
databases.</p>
|
databases.</p>
|
||||||
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/sqlite3@0.0.1")
|
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/sqlite3@0.0.3")
|
||||||
|
|
||||||
; opening DBs can fail, for the purposes of this example we
|
; opening DBs can fail, for the purposes of this example we
|
||||||
; ignore that
|
; ignore that
|
||||||
(let-do [db (Result.unsafe-from-success (SQLite3.open "db"))]
|
(defn main []
|
||||||
; we can prepare statements
|
(let-do [db (Result.unsafe-from-success (SQLite3.open "db"))]
|
||||||
(ignore
|
; Let's make sure our table is there
|
||||||
(SQLite3.query &db "INSERT INTO mytable VALUES (?1, ?2);"
|
(ignore
|
||||||
&[(to-sqlite3 @"hello") (to-sqlite3 100)]))
|
(SQLite3.query &db
|
||||||
; and query things
|
"CREATE TABLE IF NOT EXISTS mytable (name TEXT, age INT)"
|
||||||
(println* &(SQLite3.query &db "SELECT * from mytable;" &[]))
|
&[]))
|
||||||
(SQLite3.close db)
|
|
||||||
|
; we can prepare statements
|
||||||
|
(ignore
|
||||||
|
(SQLite3.query &db
|
||||||
|
"INSERT INTO mytable VALUES (?1, ?2);"
|
||||||
|
&[(to-sqlite3 @"Carp") (to-sqlite3 4)]))
|
||||||
|
|
||||||
|
; and query things
|
||||||
|
(println* &(SQLite3.query &db "SELECT * from mytable;" &[]))
|
||||||
|
(SQLite3.close db)))
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<p>Because <code>open</code> and <code>query</code> return <code>Result</code> types, we could also use
|
<p>Because <code>open</code> and <code>query</code> return <code>Result</code> types, we could also use
|
||||||
combinators!</p>
|
combinators!</p>
|
||||||
@@ -109,7 +118,7 @@ primitive Carp types can be casted to appropriate SQLite types by using the
|
|||||||
external
|
external
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [SQLite] ())
|
(Fn [SQLite] ())
|
||||||
</p>
|
</p>
|
||||||
<span>
|
<span>
|
||||||
|
|
||||||
@@ -129,7 +138,7 @@ primitive Carp types can be casted to appropriate SQLite types by using the
|
|||||||
defn
|
defn
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [&String] (Result SQLite String))
|
(Fn [(Ref String a)] (Result SQLite String))
|
||||||
</p>
|
</p>
|
||||||
<pre class="args">
|
<pre class="args">
|
||||||
(open s)
|
(open s)
|
||||||
@@ -150,7 +159,7 @@ primitive Carp types can be casted to appropriate SQLite types by using the
|
|||||||
defn
|
defn
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<p class="sig">
|
||||||
(λ [(Ref SQLite), &String, (Ref (Array Type))] (Result (Array (Array Type)) String))
|
(Fn [(Ref SQLite a), (Ref String b), (Ref (Array Type) c)] (Result (Array (Array Type)) String))
|
||||||
</p>
|
</p>
|
||||||
<pre class="args">
|
<pre class="args">
|
||||||
(query db s p)
|
(query db s p)
|
||||||
|
15
gendocs.carp
15
gendocs.carp
@@ -1,13 +1,10 @@
|
|||||||
(load "sqlite3.carp")
|
(load "sqlite3.carp")
|
||||||
|
|
||||||
(defndynamic gendocs []
|
(Project.config "title" "sqlite3")
|
||||||
(do
|
(Project.config "docs-directory" "./docs/")
|
||||||
(Project.config "title" "sqlite3")
|
(Project.config "docs-logo" "")
|
||||||
(Project.config "docs-directory" "./docs/")
|
(Project.config "docs-styling" "style.css")
|
||||||
(Project.config "docs-logo" "")
|
(Project.config "docs-generate-index" false)
|
||||||
(Project.config "docs-styling" "style.css")
|
(save-docs SQLite3)
|
||||||
(Project.config "docs-generate-index" false)
|
|
||||||
(save-docs SQLite3)))
|
|
||||||
|
|
||||||
(gendocs)
|
|
||||||
(quit)
|
(quit)
|
||||||
|
25
sqlite3.carp
25
sqlite3.carp
@@ -20,14 +20,23 @@ databases.
|
|||||||
|
|
||||||
; opening DBs can fail, for the purposes of this example we
|
; opening DBs can fail, for the purposes of this example we
|
||||||
; ignore that
|
; ignore that
|
||||||
(let-do [db (Result.unsafe-from-success (SQLite3.open \"db\"))]
|
(defn main []
|
||||||
; we can prepare statements
|
(let-do [db (Result.unsafe-from-success (SQLite3.open \"db\"))]
|
||||||
(ignore
|
; Let's make sure our table is there
|
||||||
(SQLite3.query &db \"INSERT INTO mytable VALUES (?1, ?2);\"
|
(ignore
|
||||||
&[(to-sqlite3 @\"hello\") (to-sqlite3 100)]))
|
(SQLite3.query &db
|
||||||
; and query things
|
\"CREATE TABLE IF NOT EXISTS mytable (name TEXT, age INT)\"
|
||||||
(println* &(SQLite3.query &db \"SELECT * from mytable;\" &[]))
|
&[]))
|
||||||
(SQLite3.close db)
|
|
||||||
|
; we can prepare statements
|
||||||
|
(ignore
|
||||||
|
(SQLite3.query &db
|
||||||
|
\"INSERT INTO mytable VALUES (?1, ?2);\"
|
||||||
|
&[(to-sqlite3 @\"Carp\") (to-sqlite3 4)]))
|
||||||
|
|
||||||
|
; and query things
|
||||||
|
(println* &(SQLite3.query &db \"SELECT * from mytable;\" &[]))
|
||||||
|
(SQLite3.close db)))
|
||||||
```
|
```
|
||||||
|
|
||||||
Because `open` and `query` return `Result` types, we could also use
|
Because `open` and `query` return `Result` types, we could also use
|
||||||
|
Reference in New Issue
Block a user