diff options
| author | 2021-01-26 00:37:39 +0100 | |
|---|---|---|
| committer | 2021-01-26 00:37:39 +0100 | |
| commit | b27c751320bd224be4eb3e68796d9358688c2cf6 (patch) | |
| tree | cb7b7a578f08e2ef9f60f60b02b85394a2fc652e | |
| parent | ci: stop building with the bundled sqlite on aarch64 (diff) | |
| parent | keep the same case for 'sqlite' everywhere (diff) | |
| download | zig-sqlite-b27c751320bd224be4eb3e68796d9358688c2cf6.tar.gz zig-sqlite-b27c751320bd224be4eb3e68796d9358688c2cf6.tar.xz zig-sqlite-b27c751320bd224be4eb3e68796d9358688c2cf6.zip | |
Merge branch 'improve-readme'
Diffstat (limited to '')
| -rw-r--r-- | README.md | 38 |
1 files changed, 29 insertions, 9 deletions
| @@ -13,10 +13,10 @@ If you use this library, expect to have to make changes when you update the code | |||
| 13 | [Zig master](https://ziglang.org/download/) is the only required dependency. | 13 | [Zig master](https://ziglang.org/download/) is the only required dependency. |
| 14 | 14 | ||
| 15 | For sqlite, you have options depending on your target: | 15 | For sqlite, you have options depending on your target: |
| 16 | * On Windows the only supported way at the moment to build `zig-sqlite` is with the embedded sqlite source code file. | 16 | * On Windows the only supported way at the moment to build `zig-sqlite` is with the bundled sqlite source code file. |
| 17 | * On Linux we have to options: | 17 | * On Linux we have two options: |
| 18 | * use the system and development package for sqlite (`libsqlite3-dev` for Debian and derivatives, `sqlite3-devel` for Fedora) | 18 | * use the system and development package for sqlite (`libsqlite3-dev` for Debian and derivatives, `sqlite3-devel` for Fedora) |
| 19 | * use the embedded sqlite source code file. | 19 | * use the bundled sqlite source code file. |
| 20 | 20 | ||
| 21 | # Features | 21 | # Features |
| 22 | 22 | ||
| @@ -28,25 +28,45 @@ For sqlite, you have options depending on your target: | |||
| 28 | Since there's no package manager for Zig yet, the recommended way is to use a git submodule: | 28 | Since there's no package manager for Zig yet, the recommended way is to use a git submodule: |
| 29 | 29 | ||
| 30 | ```bash | 30 | ```bash |
| 31 | $ git submodule add https://github.com/vrischmann/zig-sqlite.git src/sqlite | 31 | $ git submodule add https://github.com/vrischmann/zig-sqlite.git third_party/zig-sqlite |
| 32 | ``` | 32 | ``` |
| 33 | 33 | ||
| 34 | Then add the following to your `build.zig` target(s): | 34 | ## Using the system sqlite library |
| 35 | |||
| 36 | If you want to use the system sqlite library, add the following to your `build.zig` target(s): | ||
| 35 | 37 | ||
| 36 | ```zig | 38 | ```zig |
| 37 | exe.linkLibC(); | 39 | exe.linkLibC(); |
| 38 | exe.linkSystemLibrary("sqlite3"); | 40 | exe.linkSystemLibrary("sqlite3"); |
| 39 | exe.addPackage(.{ .name = "sqlite", .path = "src/sqlite/sqlite.zig" }); | 41 | exe.addPackage(.{ .name = "sqlite", .path = "third_party/zig-sqlite/sqlite.zig" }); |
| 40 | ``` | 42 | ``` |
| 41 | 43 | ||
| 42 | Now you should be able to import sqlite like this: | 44 | ## Using the bundled sqlite source code file |
| 45 | |||
| 46 | If you want to use the bundled sqlite source code file, first you need to add it as a static library in your `build.zig` file: | ||
| 43 | 47 | ||
| 44 | ```zig | 48 | ```zig |
| 45 | const sqlite = @import("sqlite"); | 49 | const sqlite = b.addStaticLibrary("sqlite", null); |
| 50 | sqlite.addCSourceFile("third_party/zig-sqlite/sqlite3.c", &[_][]const u8{"-std=c99"}); | ||
| 51 | sqlite.linkLibC(); | ||
| 52 | ``` | ||
| 53 | |||
| 54 | Now it's just a matter of linking your `build.zig` target(s) to this library instead of the system one: | ||
| 55 | |||
| 56 | ```zig | ||
| 57 | exe.linkLibC(); | ||
| 58 | exe.linkLibrary(sqlite); | ||
| 59 | exe.addPackage(.{ .name = "sqlite", .path = "third_party/zig-sqlite/sqlite.zig" }); | ||
| 46 | ``` | 60 | ``` |
| 47 | 61 | ||
| 48 | # Usage | 62 | # Usage |
| 49 | 63 | ||
| 64 | Import `zig-sqlite` like this: | ||
| 65 | |||
| 66 | ```zig | ||
| 67 | const sqlite = @import("sqlite"); | ||
| 68 | ``` | ||
| 69 | |||
| 50 | ## Initialization | 70 | ## Initialization |
| 51 | 71 | ||
| 52 | You must create and initialize an instance of `sqlite.Db`: | 72 | You must create and initialize an instance of `sqlite.Db`: |
| @@ -129,7 +149,7 @@ while (id < 20) : (id += 1) { | |||
| 129 | 149 | ||
| 130 | For queries which return data you have multiple options: | 150 | For queries which return data you have multiple options: |
| 131 | * `Statement.all` which takes an allocator and can allocate memory. | 151 | * `Statement.all` which takes an allocator and can allocate memory. |
| 132 | * `Statement.one` which does not take an allocator and cannot allocate memory (aside from what SQLite allocates itself). | 152 | * `Statement.one` which does not take an allocator and cannot allocate memory (aside from what sqlite allocates itself). |
| 133 | * `Statement.oneAlloc` which takes an allocator and can allocate memory. | 153 | * `Statement.oneAlloc` which takes an allocator and can allocate memory. |
| 134 | 154 | ||
| 135 | ### Type parameter | 155 | ### Type parameter |