diff options
| -rw-r--r-- | README.md | 80 |
1 files changed, 43 insertions, 37 deletions
| @@ -19,38 +19,44 @@ So your mileage may vary if you try to use `zig-sqlite`. | |||
| 19 | 19 | ||
| 20 | # Table of contents | 20 | # Table of contents |
| 21 | 21 | ||
| 22 | * [Status](#status) | 22 | <!--toc:start--> |
| 23 | * [Requirements](#requirements) | 23 | - [zig-sqlite](#zig-sqlite) |
| 24 | * [Features](#features) | 24 | - [Status](#status) |
| 25 | * [Installation](#installation) | 25 | - [Zig release support](#zig-release-support) |
| 26 | * [Official package manager](#official-package-manager) | 26 | - [Table of contents](#table-of-contents) |
| 27 | * [zigmod](#zigmod) | 27 | - [Requirements](#requirements) |
| 28 | * [Git submodule](#git-submodule) | 28 | - [Features](#features) |
| 29 | * [Using the system sqlite library](#using-the-system-sqlite-library) | 29 | - [Installation](#installation) |
| 30 | * [Using the bundled sqlite source code file](#using-the-bundled-sqlite-source-code-file) | 30 | - [Official package manager](#official-package-manager) |
| 31 | * [Usage](#usage) | 31 | - [zigmod](#zigmod) |
| 32 | * [Initialization](#initialization) | 32 | - [Git submodule](#git-submodule) |
| 33 | * [Preparing a statement](#preparing-a-statement) | 33 | - [Using the system sqlite library](#using-the-system-sqlite-library) |
| 34 | * [Common use](#common-use) | 34 | - [Using the bundled sqlite source code file](#using-the-bundled-sqlite-source-code-file) |
| 35 | * [Diagnostics](#diagnostics) | 35 | - [Usage](#usage) |
| 36 | * [Executing a statement](#executing-a-statement) | 36 | - [Demo](#demo) |
| 37 | * [Reuse a statement](#reuse-a-statement) | 37 | - [Initialization](#initialization) |
| 38 | * [Reading data](#reading-data) | 38 | - [Preparing a statement](#preparing-a-statement) |
| 39 | * [Type parameter](#type-parameter) | 39 | - [Common use](#common-use) |
| 40 | * [Non allocating](#non-allocating) | 40 | - [Diagnostics](#diagnostics) |
| 41 | * [Allocating](#allocating) | 41 | - [Executing a statement](#executing-a-statement) |
| 42 | * [Iterating](#iterating) | 42 | - [Reuse a statement](#reuse-a-statement) |
| 43 | * [Non allocating](#non-allocating-1) | 43 | - [Reading data in one go](#reading-data-in-one-go) |
| 44 | * [Allocating](#allocating-1) | 44 | - [Type parameter](#type-parameter) |
| 45 | * [Bind parameters and resultset rows](#bind-parameters-and-resultset-rows) | 45 | - [`Statement.one`](#statementone) |
| 46 | * [Custom type binding and reading](#custom-type-binding-and-reading) | 46 | - [`Statement.all` and `Statement.oneAlloc`](#statementall-and-statementonealloc) |
| 47 | * [Note about complex allocations](#note-about-complex-allocations) | 47 | - [Iterating](#iterating) |
| 48 | * [Comptime checks](#comptime-checks) | 48 | - [`Iterator.next`](#iteratornext) |
| 49 | * [Check the number of bind parameters.](#check-the-number-of-bind-parameters) | 49 | - [`Iterator.nextAlloc`](#iteratornextalloc) |
| 50 | * [Assign types to bind markers and check them.](#assign-types-to-bind-markers-and-check-them) | 50 | - [Bind parameters and resultset rows](#bind-parameters-and-resultset-rows) |
| 51 | * [User defined SQL functions](#user-defined-sql-functions) | 51 | - [Custom type binding and reading](#custom-type-binding-and-reading) |
| 52 | * [Scalar functions](#scalar-functions) | 52 | - [Note about complex allocations](#note-about-complex-allocations) |
| 53 | * [Aggregate functions](#aggregate-functions) | 53 | - [Comptime checks](#comptime-checks) |
| 54 | - [Check the number of bind parameters.](#check-the-number-of-bind-parameters) | ||
| 55 | - [Assign types to bind markers and check them.](#assign-types-to-bind-markers-and-check-them) | ||
| 56 | - [User defined SQL functions](#user-defined-sql-functions) | ||
| 57 | - [Scalar functions](#scalar-functions) | ||
| 58 | - [Aggregate functions](#aggregate-functions) | ||
| 59 | <!--toc:end--> | ||
| 54 | 60 | ||
| 55 | # Requirements | 61 | # Requirements |
| 56 | 62 | ||
| @@ -297,7 +303,7 @@ while (id < 20) : (id += 1) { | |||
| 297 | } | 303 | } |
| 298 | ``` | 304 | ``` |
| 299 | 305 | ||
| 300 | ## Reading data | 306 | ## Reading data in one go |
| 301 | 307 | ||
| 302 | For queries which return data you have multiple options: | 308 | For queries which return data you have multiple options: |
| 303 | * `Statement.all` which takes an allocator and can allocate memory. | 309 | * `Statement.all` which takes an allocator and can allocate memory. |
| @@ -316,7 +322,7 @@ The type can be a pointer but only when using the methods taking an allocator. | |||
| 316 | 322 | ||
| 317 | Not all types are allowed, see the section "Bind parameters and resultset rows" for more information on the types mapping rules. | 323 | Not all types are allowed, see the section "Bind parameters and resultset rows" for more information on the types mapping rules. |
| 318 | 324 | ||
| 319 | ### Non allocating | 325 | ### `Statement.one` |
| 320 | 326 | ||
| 321 | Using `one`: | 327 | Using `one`: |
| 322 | 328 | ||
| @@ -379,7 +385,7 @@ if (row) |age| { | |||
| 379 | } | 385 | } |
| 380 | ``` | 386 | ``` |
| 381 | 387 | ||
| 382 | ### Allocating | 388 | ### `Statement.all` and `Statement.oneAlloc` |
| 383 | 389 | ||
| 384 | Using `all`: | 390 | Using `all`: |
| 385 | 391 | ||
| @@ -430,7 +436,7 @@ Iterating is done by calling the `next` or `nextAlloc` method on an iterator. Ju | |||
| 430 | 436 | ||
| 431 | `next` or `nextAlloc` will either return an optional value or an error; you should keep iterating until `null` is returned. | 437 | `next` or `nextAlloc` will either return an optional value or an error; you should keep iterating until `null` is returned. |
| 432 | 438 | ||
| 433 | ### Non allocating | 439 | ### `Iterator.next` |
| 434 | 440 | ||
| 435 | ```zig | 441 | ```zig |
| 436 | var stmt = try db.prepare("SELECT age FROM user WHERE age < ?"); | 442 | var stmt = try db.prepare("SELECT age FROM user WHERE age < ?"); |
| @@ -445,7 +451,7 @@ while (try iter.next(.{})) |age| { | |||
| 445 | } | 451 | } |
| 446 | ``` | 452 | ``` |
| 447 | 453 | ||
| 448 | ### Allocating | 454 | ### `Iterator.nextAlloc` |
| 449 | 455 | ||
| 450 | ```zig | 456 | ```zig |
| 451 | var stmt = try db.prepare("SELECT name FROM user WHERE age < ?"); | 457 | var stmt = try db.prepare("SELECT name FROM user WHERE age < ?"); |