Closed vrischmann closed 2 years ago
I've ended up with an API for filter
that's not too bad:
pub const FilterArg = struct {
value: ?*c.sqlite3_value,
pub fn as(self: FilterArg, comptime Type: type) Type {
...
}
};
pub fn filter(cursor: *Cursor, diags: *sqlite.vtab.VTabDiagnostics, index: sqlite.vtab.IndexIdentifier, args: []sqlite.vtab.FilterArg) FilterError!void {
...
}
you would use the arg like this:
const arg1 = filter_arg1.as([]const u8);
const arg2 = filter_arg2.as(usize);
...
as
uses helpers.setTypeFromValue
which is also used for the arguments of a user function.
Still to do:
xCreate
and xDestroy
connect
, disconnect
called by xConnect
and xDisconnect
respectivelyxCreate
I'm not going to implement all the "write" functions (xUpdate
etc); this will come at a later point.
For tests I'm thinking I could pass a bunch of random parameters as arguments to the virtual table creation, then since I know these parameters I can check that the rows I fetched match the rows generated.
Yes, I think we need some C stuff to glue zig code, there is a go library use similar tricks.
https://github.com/riyaz-ali/sqlite/blob/master/extension.c
In extension.c, it will call a go func go_sqlite3_extension_init
, and go_sqlite3_extension_init
is an exported FFI function which used to bridge C and Go code.
https://github.com/riyaz-ali/sqlite/blob/master/_examples/series/series.go
This is a demo to to write gen_series
module in Go
Hope this help you.
Thanks ! I'll take a look at your links once I get back to working on building an extension.
The abiilty to build loadable extensions is part of #112 now. This PR will focus only on virtual tables.
I'm still not 100% sure when/how to use xCreate vs xConnect and xDestroy vs xDisconnect, I think I'll implement in another PR. The arguments are now parsed into a more usable type.
I'll focus next on improving tests and that will be it for this PR I think.
Initial work on virtual tables. The goal is to be able to easily create virtual tables using Zig and expose as little as possible of the C-ism of the raw sqlite interface.
Currently implementing a virtual table is done by providing a
Table
type which must implement the following:The cursor type must implement the following:
It's relatively complete and should largely abstract the raw sqlite interface but one thing is missing: passing the arguments to the
filter
function. SQLite gives us an array ofsqlite3_value
and I'll have to think longer on how I want to convert this to idiomatic Zig types.I'm building a demo here (not completely ready yet)