Skip to content

Commit 5df090a

Browse files
ioplkerlpil
authored andcommitted
Add docs to exec() and query()
1 parent 345a383 commit 5df090a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/sqlight.gleam

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub type Error {
1919
code: ErrorCode,
2020
message: String,
2121
/// If the most recent error references a specific token in the input SQL,
22-
/// this is the byte offset of the start of that token.
22+
/// this is the byte offset of the start of that token.
2323
/// If the most recent error does not reference a specific token, this is -1.
2424
offset: Int,
2525
)
@@ -320,15 +320,15 @@ fn close_(a: Connection) -> Result(Nil, Error)
320320
/// ```gleam
321321
/// let assert Ok(conn) = open("file:data.sqlite3")
322322
/// ```
323-
///
323+
///
324324
/// ## Opens "data.db" in read only mode with a private cache
325-
///
325+
///
326326
/// ```gleam
327327
/// let assert Ok(conn) = open("file:data.db?mode=ro&cache=private")
328328
/// ```
329-
///
330-
/// Opens a shared memory database named memdb1 with a shared cache.
331-
///
329+
///
330+
/// Opens a shared memory database named memdb1 with a shared cache.
331+
///
332332
/// ```gleam
333333
/// let assert Ok(conn) = open("file:memdb1?mode=memory&cache=shared")
334334
/// ```
@@ -347,7 +347,7 @@ pub fn close(connection: Connection) -> Result(Nil, Error) {
347347
close_(connection)
348348
}
349349

350-
/// Open a connection to a SQLite database and execute a function with it,.try
350+
/// Open a connection to a SQLite database and execute a function with it, then
351351
/// close the connection.
352352
///
353353
/// This function works well with a `use` expression to automatically close the
@@ -371,10 +371,19 @@ pub fn with_connection(path: String, f: fn(Connection) -> a) -> a {
371371
value
372372
}
373373

374+
/// Execute one or more sql statements without returning the results.
374375
pub fn exec(sql: String, on connection: Connection) -> Result(Nil, Error) {
375376
exec_(sql, connection)
376377
}
377378

379+
/// Execute a sql statement and try to decode the result.
380+
///
381+
/// # Caveats
382+
///
383+
/// Only the first semicolon delimited sql statement will be executed.
384+
///
385+
/// Use `exec()` if you need to run some other statements before
386+
/// doing the select (e.g., attaching another database in this connection).
378387
pub fn query(
379388
sql: String,
380389
on connection: Connection,

0 commit comments

Comments
 (0)