diff --git a/build.zig b/build.zig index 88fed1c..95a299d 100644 --- a/build.zig +++ b/build.zig @@ -7,24 +7,12 @@ pub fn build(b: *std.Build) !void { const exe = b.addExecutable(.{ .name = "zuletzt", - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); // Example dependency: - const iguanas_dep = b.dependency("iguanas", .{ .optimize = optimize, .target = target }); - exe.root_module.addImport("iguanas", iguanas_dep.module("iguanas")); - - const sqlite = b.dependency("sqlite", .{ - .target = target, - .optimize = optimize, - }); - - exe.root_module.addImport("sqlite", sqlite.module("sqlite")); - - // links the bundled sqlite3, so leave this out if you link the system one - exe.linkLibrary(sqlite.artifact("sqlite")); // All dependencies **must** be added to imports above this line. @@ -41,7 +29,7 @@ pub fn build(b: *std.Build) !void { run_step.dependOn(&run_cmd.step); const lib_unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -49,7 +37,7 @@ pub fn build(b: *std.Build) !void { const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); const exe_unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); diff --git a/build.zig.zon b/build.zig.zon index 54425ff..9b7f253 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -16,12 +16,8 @@ // internet connectivity. .dependencies = .{ .jetzig = .{ - .url = "https://github.com/jetzig-framework/jetzig/archive/3c47435fd6ec7ea705a778dab1f533ae74e9bd6a.tar.gz", - .hash = "12209edf5716323a2475a4fe0eb02f5281d8b1d5e6708bc03a104892f7cf72a6cab5", - }, - .sqlite = .{ - .url = "https://github.com/vrischmann/zig-sqlite/archive/706ec59.tar.gz", - .hash = "1220faeb7e1b89ce805a41be1395931fbec69530aac45fce9cb17b817532e4cb6899", + .url = "https://github.com/jetzig-framework/jetzig/archive/dda433bb73000614482af10a277d47dc9d89600c.tar.gz", + .hash = "12202ce84b803a8b300c91d98afbc7c326298b55a23bf05cf603182e934b621008ec", }, }, .paths = .{ diff --git a/src/app/views/search.zig b/src/app/views/search.zig deleted file mode 100644 index 46d1592..0000000 --- a/src/app/views/search.zig +++ /dev/null @@ -1,52 +0,0 @@ -const std = @import("std"); -const jetzig = @import("jetzig"); -const queries = @import("../lib/db.zig"); -const sqlite = @import("sqlite"); - -pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - var root = try data.array(); - var gpa = std.heap.GeneralPurposeAllocator(.{}){}; - const allocator = gpa.allocator(); - var arena = std.heap.ArenaAllocator.init(allocator); - defer arena.deinit(); - 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 params = try request.params(); - const queryOrNull: ?[]const u8 = if (params.get("q")) |param| param.string.value else null; - if (queryOrNull) |query| { - // sql.search(query, db); - var artistSearch = try db.prepare(queries.total_search); - defer artistSearch.deinit(); - - const artistResults = try artistSearch.all( - struct { - artist: []u8, - url: []u8, - form: []u8, - }, - arena.allocator(), - .{}, - .{ .artist = query, .album = query, .track = query }, - ); - - for (artistResults) |r| { - std.log.debug("artist: {s}, url: {s}", .{ r.artist, r.url }); - try root.append(data.string(r.artist)); - try root.append(data.string(r.url)); - try root.append(data.string(r.form)); - //std.log.debug("{s}", .{r}); - } - } else { - return request.render(.bad_request); - } - //const query = params.get("q"); - //try root.put("q",query); - //try root.put("q", data.string("Welcome")); - return request.render(.ok); -} diff --git a/src/app/views/search/index.zmpl b/src/app/views/search/index.zmpl deleted file mode 100644 index 4101944..0000000 --- a/src/app/views/search/index.zmpl +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - @zig { - for (zmpl.items(.array), 0..) |u,i| { - if(@mod(i,3)==0){ - - - - } - } - } -
ArtistAlbumTrack
{{u}}
\ No newline at end of file diff --git a/src/main.zig b/src/main.zig index fea50c2..ec577ff 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,10 +1,10 @@ const std = @import("std"); - -pub const jetzig = @import("jetzig"); - +const jetzig = @import("jetzig"); pub const routes = @import("routes"); +const zmd = @import("zmd"); +const builtin = @import("builtin"); +pub const static = @import("static"); -pub const sqlite = @import("sqlite"); // Override default settings in `jetzig.config` here: pub const jetzig_options = struct { @@ -72,13 +72,13 @@ pub const jetzig_options = struct { "", }; - pub fn block(allocator: std.mem.Allocator, node: jetzig.zmd.Node) ![]const u8 { + pub fn block(allocator: std.mem.Allocator, node: zmd.Node) ![]const u8 { return try std.fmt.allocPrint(allocator, \\
{s}
, .{ node.meta, node.content }); } - pub fn link(allocator: std.mem.Allocator, node: jetzig.zmd.Node) ![]const u8 { + pub fn link(allocator: std.mem.Allocator, node: zmd.Node) ![]const u8 { return try std.fmt.allocPrint(allocator, \\{1s} , .{ node.href.?, node.title.? });