Begin SQL testing

This commit is contained in:
Samuel Webb 2024-04-07 15:41:57 -04:00
parent a3a5e37225
commit fee65c4b9d
3 changed files with 35 additions and 2 deletions

View file

@ -24,8 +24,8 @@
.hash = "12202fd319a5ab4e124b00e8ddea474d07c19c4e005d77b6c29fc44860904ea01a5c",
},
.sqlite = .{
.url = "https://github.com/vrischmann/zig-sqlite/archive/a3095ac.tar.gz",
.hash = "12203f7d14722debe8f1a2168f28a262aaa5ec2457a7a975fc7dcc1123ed11597c98",
.url = "https://github.com/vrischmann/zig-sqlite/archive/6af21bb.tar.gz",
.hash = "12202799861d92c7880d1a74f95be099752d7f0420a0c9628dc923ca2b1a22b7bda8",
}
},
.paths = .{

0
src/db.zig Normal file
View file

View file

@ -4,6 +4,8 @@ pub const jetzig = @import("jetzig");
pub const routes = @import("routes");
pub const sqlite = @import("sqlite");
// Override default settings in `jetzig.config` here:
pub const jetzig_options = struct {
/// Middleware chain. Add any custom middleware here, or use middleware provided in
@ -85,6 +87,37 @@ pub const jetzig_options = struct {
};
pub fn main() !void {
var db = try sqlite.Db.init(.{
.mode = sqlite.Db.Mode{ .File = "/home/swebb/Source/zuletzt/src/app/database/data.db" },
.open_flags = .{
.write = true,
.create = true,
},
.threading_mode = .MultiThread,
});
const create =
\\CREATE TABLE artists ('artist', 'plays')
;
const query =
\\INSERT INTO artists ('artist', 'plays') VALUES (?,?)
;
var build = try db.prepare(create);
defer build.deinit();
try build.exec(.{},.{});
var stmt = try db.prepare(query);
defer stmt.deinit();
try stmt.exec(.{}, .{
.artist = "Wilco",
.plays = 2500,
});
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer std.debug.assert(gpa.deinit() == .ok);
const allocator = gpa.allocator();