From e819a2c4663a6cef9b1400e69ad14438328b524b Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Tue, 26 Jan 2021 00:32:42 +0100 Subject: update readme Add more information about building with the system sqlite library or the bundled sqlite source file. --- README.md | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 96dfcde..ddeaf89 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ If you use this library, expect to have to make changes when you update the code [Zig master](https://ziglang.org/download/) is the only required dependency. For sqlite, you have options depending on your target: -* On Windows the only supported way at the moment to build `zig-sqlite` is with the embedded sqlite source code file. +* On Windows the only supported way at the moment to build `zig-sqlite` is with the bundled sqlite source code file. * On Linux we have to options: * use the system and development package for sqlite (`libsqlite3-dev` for Debian and derivatives, `sqlite3-devel` for Fedora) - * use the embedded sqlite source code file. + * use the bundled sqlite source code file. # Features @@ -28,25 +28,45 @@ For sqlite, you have options depending on your target: Since there's no package manager for Zig yet, the recommended way is to use a git submodule: ```bash -$ git submodule add https://github.com/vrischmann/zig-sqlite.git src/sqlite +$ git submodule add https://github.com/vrischmann/zig-sqlite.git third_party/zig-sqlite ``` -Then add the following to your `build.zig` target(s): +## Using the system sqlite library + +If you want to use the system sqlite library, add the following to your `build.zig` target(s): ```zig exe.linkLibC(); exe.linkSystemLibrary("sqlite3"); -exe.addPackage(.{ .name = "sqlite", .path = "src/sqlite/sqlite.zig" }); +exe.addPackage(.{ .name = "sqlite", .path = "third_party/zig-sqlite/sqlite.zig" }); ``` -Now you should be able to import sqlite like this: +## Using the bundled sqlite source code file + +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: ```zig -const sqlite = @import("sqlite"); +const sqlite = b.addStaticLibrary("sqlite", null); +sqlite.addCSourceFile("third_party/zig-sqlite/sqlite3.c", &[_][]const u8{"-std=c99"}); +sqlite.linkLibC(); +``` + +Now it's just a matter of linking your `build.zig` target(s) to this library instead of the system one: + +```zig +exe.linkLibC(); +exe.linkLibrary(sqlite); +exe.addPackage(.{ .name = "sqlite", .path = "third_party/zig-sqlite/sqlite.zig" }); ``` # Usage +Import `zig-sqlite` like this: + +```zig +const sqlite = @import("sqlite"); +``` + ## Initialization You must create and initialize an instance of `sqlite.Db`: -- cgit v1.2.3 From 194ab4cc084718d4f031b0707cef0c17de83c178 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Tue, 26 Jan 2021 00:35:12 +0100 Subject: fix typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index ddeaf89..39df035 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ If you use this library, expect to have to make changes when you update the code For sqlite, you have options depending on your target: * On Windows the only supported way at the moment to build `zig-sqlite` is with the bundled sqlite source code file. -* On Linux we have to options: +* On Linux we have two options: * use the system and development package for sqlite (`libsqlite3-dev` for Debian and derivatives, `sqlite3-devel` for Fedora) * use the bundled sqlite source code file. -- cgit v1.2.3 From aa78eb0511e0d1b053050c378fbe801b46e8445a Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Tue, 26 Jan 2021 00:37:21 +0100 Subject: keep the same case for 'sqlite' everywhere --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 39df035..f1f2e09 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ while (id < 20) : (id += 1) { For queries which return data you have multiple options: * `Statement.all` which takes an allocator and can allocate memory. -* `Statement.one` which does not take an allocator and cannot allocate memory (aside from what SQLite allocates itself). +* `Statement.one` which does not take an allocator and cannot allocate memory (aside from what sqlite allocates itself). * `Statement.oneAlloc` which takes an allocator and can allocate memory. ### Type parameter -- cgit v1.2.3