Closed nathananderson98 closed 1 year ago
Hi,
it would be great if you could submit a PR! Thanks.
I tried to push a branch up but it says I don't have access, do I need to like create my own Fork and then merge request it in?
I tried to push a branch up but it says I don't have access, do I need to like create my own Fork and then merge request it in?
Yes, that's the process. If you're not familiar with PR I can suggest the official GitHub documentation on this topic which is quite good.
Sorry its been a few days, happy to get working on that today!
As an aside, I just spent the last few days writing up some functions to create SQLite queries (SELECT, UPDATE, etc) as well as Table migration queries based on Types using comptime type reflection. Would this be something helpful to include in the repo somewhere? Or is this best left out? I only bring it up because I figure it could be helpful to others.
As an example, here is what the function looks like for creating an update query:
pub inline fn createUpdateQuery(comptime Type: type) []const u8 {
comptime {
var query: []const u8 = "UPDATE " ++ getTypeTableName(Type) ++ " SET ";
inline for (@typeInfo(Type).Struct.fields, 0..) |field, i| {
if (i != 0) {
query = query ++ " = ?, ";
}
query = query ++ field.name;
}
query = query ++ " = ? WHERE id = ?;";
return query;
}
}
Then calling the function like this: query = createUpdateQuery(@TypeOf(.{.id = 1, .name = "Johnny", .email = "secret@mail.net"}));
gives:
UPDATE users SET id = ?, name = ?, email = ? WHERE id = ?;
So it's a query builder essentially ? It could be put in a query_builder.zig
file, exported and referenced with sqlite.query_builder
.
So something like:
const query = sqlite.query_builder.createUpdateQuery(@TypeOf(.{.id = 1, .name = "Johnny", .email = "secret@mail.net"}));
What do you think ?
Working on a PR right now, hopefully can have it up later today.
Hi, it's been a while now.
I just fixed the linking instructions in the readme, addressing your original issue. Feel free to open another issue or submit a PR for the query builder stuff you mentioned.
Took me a bit of time looking through the std lib and discord to get the right calls, just two changed when linking with the bundled sqlite source code. I have a branch with the two readme edits I'm happy to submit to PR.
Changed relevant Readme section to:
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:If you need to define custom compile-time options for sqlite, modify the flags (second argument to
addCSourceFile
).Now it's just a matter of linking your
build.zig
target(s) to this library instead of the system one: