diff options
| author | 2022-08-15 21:53:24 +0200 | |
|---|---|---|
| committer | 2022-09-18 20:11:36 +0200 | |
| commit | b226ff2ca5956f81c115202af63d1bb3502d41df (patch) | |
| tree | 1b5fb0e4af4801659dbaf620420d99682bcd8d0b /sqlite.zig | |
| parent | move test helpers (diff) | |
| download | zig-sqlite-b226ff2ca5956f81c115202af63d1bb3502d41df.tar.gz zig-sqlite-b226ff2ca5956f81c115202af63d1bb3502d41df.tar.xz zig-sqlite-b226ff2ca5956f81c115202af63d1bb3502d41df.zip | |
add the virtual table implementation
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 25 |
1 files changed, 25 insertions, 0 deletions
| @@ -20,8 +20,13 @@ const getLastDetailedErrorFromDb = errors.getLastDetailedErrorFromDb; | |||
| 20 | const getDetailedErrorFromResultCode = errors.getDetailedErrorFromResultCode; | 20 | const getDetailedErrorFromResultCode = errors.getDetailedErrorFromResultCode; |
| 21 | 21 | ||
| 22 | const getTestDb = @import("test.zig").getTestDb; | 22 | const getTestDb = @import("test.zig").getTestDb; |
| 23 | pub const vtab = @import("vtab.zig"); | ||
| 23 | const helpers = @import("helpers.zig"); | 24 | const helpers = @import("helpers.zig"); |
| 24 | 25 | ||
| 26 | test { | ||
| 27 | _ = @import("vtab.zig"); | ||
| 28 | } | ||
| 29 | |||
| 25 | const logger = std.log.scoped(.sqlite); | 30 | const logger = std.log.scoped(.sqlite); |
| 26 | 31 | ||
| 27 | /// Text is used to represent a SQLite TEXT value when binding a parameter or reading a column. | 32 | /// Text is used to represent a SQLite TEXT value when binding a parameter or reading a column. |
| @@ -787,6 +792,26 @@ pub const Db = struct { | |||
| 787 | try stmt.exec(new_options, .{}); | 792 | try stmt.exec(new_options, .{}); |
| 788 | } | 793 | } |
| 789 | } | 794 | } |
| 795 | |||
| 796 | pub fn createVirtualTable( | ||
| 797 | self: *Self, | ||
| 798 | comptime name: [:0]const u8, | ||
| 799 | module_context: *vtab.ModuleContext, | ||
| 800 | comptime Table: type, | ||
| 801 | ) !void { | ||
| 802 | const VirtualTableType = vtab.VirtualTable(name, Table); | ||
| 803 | |||
| 804 | const result = c.sqlite3_create_module_v2( | ||
| 805 | self.db, | ||
| 806 | name, | ||
| 807 | &VirtualTableType.module, | ||
| 808 | module_context, | ||
| 809 | null, | ||
| 810 | ); | ||
| 811 | if (result != c.SQLITE_OK) { | ||
| 812 | return errors.errorFromResultCode(result); | ||
| 813 | } | ||
| 814 | } | ||
| 790 | }; | 815 | }; |
| 791 | 816 | ||
| 792 | /// FunctionContext is the context passed as first parameter in the `step` and `finalize` functions used with `createAggregateFunction`. | 817 | /// FunctionContext is the context passed as first parameter in the `step` and `finalize` functions used with `createAggregateFunction`. |