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>
|
||||
<p>The module <code>SQLite3</code> provides facilities for opening, closing, and querying
|
||||
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
|
||||
; ignore that
|
||||
(let-do [db (Result.unsafe-from-success (SQLite3.open "db"))]
|
||||
; we can prepare statements
|
||||
(ignore
|
||||
(SQLite3.query &db "INSERT INTO mytable VALUES (?1, ?2);"
|
||||
&[(to-sqlite3 @"hello") (to-sqlite3 100)]))
|
||||
; and query things
|
||||
(println* &(SQLite3.query &db "SELECT * from mytable;" &[]))
|
||||
(SQLite3.close db)
|
||||
(defn main []
|
||||
(let-do [db (Result.unsafe-from-success (SQLite3.open "db"))]
|
||||
; Let's make sure our table is there
|
||||
(ignore
|
||||
(SQLite3.query &db
|
||||
"CREATE TABLE IF NOT EXISTS mytable (name TEXT, age INT)"
|
||||
&[]))
|
||||
|
||||
; 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>
|
||||
<p>Because <code>open</code> and <code>query</code> return <code>Result</code> types, we could also use
|
||||
combinators!</p>
|
||||
@@ -109,7 +118,7 @@ primitive Carp types can be casted to appropriate SQLite types by using the
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [SQLite] ())
|
||||
(Fn [SQLite] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@@ -129,7 +138,7 @@ primitive Carp types can be casted to appropriate SQLite types by using the
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Result SQLite String))
|
||||
(Fn [(Ref String a)] (Result SQLite String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(open s)
|
||||
@@ -150,7 +159,7 @@ primitive Carp types can be casted to appropriate SQLite types by using the
|
||||
defn
|
||||
</div>
|
||||
<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>
|
||||
<pre class="args">
|
||||
(query db s p)
|
||||
|
15
gendocs.carp
15
gendocs.carp
@@ -1,13 +1,10 @@
|
||||
(load "sqlite3.carp")
|
||||
|
||||
(defndynamic gendocs []
|
||||
(do
|
||||
(Project.config "title" "sqlite3")
|
||||
(Project.config "docs-directory" "./docs/")
|
||||
(Project.config "docs-logo" "")
|
||||
(Project.config "docs-styling" "style.css")
|
||||
(Project.config "docs-generate-index" false)
|
||||
(save-docs SQLite3)))
|
||||
(Project.config "title" "sqlite3")
|
||||
(Project.config "docs-directory" "./docs/")
|
||||
(Project.config "docs-logo" "")
|
||||
(Project.config "docs-styling" "style.css")
|
||||
(Project.config "docs-generate-index" false)
|
||||
(save-docs SQLite3)
|
||||
|
||||
(gendocs)
|
||||
(quit)
|
||||
|
25
sqlite3.carp
25
sqlite3.carp
@@ -20,14 +20,23 @@ databases.
|
||||
|
||||
; opening DBs can fail, for the purposes of this example we
|
||||
; ignore that
|
||||
(let-do [db (Result.unsafe-from-success (SQLite3.open \"db\"))]
|
||||
; we can prepare statements
|
||||
(ignore
|
||||
(SQLite3.query &db \"INSERT INTO mytable VALUES (?1, ?2);\"
|
||||
&[(to-sqlite3 @\"hello\") (to-sqlite3 100)]))
|
||||
; and query things
|
||||
(println* &(SQLite3.query &db \"SELECT * from mytable;\" &[]))
|
||||
(SQLite3.close db)
|
||||
(defn main []
|
||||
(let-do [db (Result.unsafe-from-success (SQLite3.open \"db\"))]
|
||||
; Let's make sure our table is there
|
||||
(ignore
|
||||
(SQLite3.query &db
|
||||
\"CREATE TABLE IF NOT EXISTS mytable (name TEXT, age INT)\"
|
||||
&[]))
|
||||
|
||||
; 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
|
||||
|
Reference in New Issue
Block a user