Moved config to libs
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
pub const BUFFER_SIZE = 1024 * 10; // Used a bit everywhere. The size for the schema for example. 10kB
|
||||
pub const MAX_FILE_SIZE = 1024 * 1024; // 1MB
|
||||
pub const CPU_CORE = 16;
|
||||
|
||||
// Testing
|
||||
pub const TEST_DATA_DIR = "data"; // Maybe put that directly in the build
|
||||
|
||||
// Debug
|
||||
pub const PRINT_STATE = false;
|
||||
pub const DONT_SEND = true;
|
||||
pub const RESET_LOG_AT_RESTART = false; // If true, will reset the log file at the start of the db, otherwise just keep adding to it
|
||||
|
||||
// Help message
|
||||
pub const HELP_MESSAGE = struct {
|
||||
pub const main: []const u8 =
|
||||
\\Welcome to ZipponDB v0.2!
|
||||
\\
|
||||
\\Available commands:
|
||||
\\run To run a query.
|
||||
\\db Create or chose a database.
|
||||
\\schema Initialize the database schema.
|
||||
\\quit Stop the CLI with memory safety.
|
||||
\\
|
||||
\\For more informations: https://mrbounty.github.io/ZipponDB/cli
|
||||
\\
|
||||
;
|
||||
pub const db: []const u8 =
|
||||
\\Available commands:
|
||||
\\new Create a new database using a path to a sub folder.
|
||||
\\use Select an existing folder to use as database.
|
||||
\\metrics Print some metrics of the current database.
|
||||
\\
|
||||
\\For more informations: https://mrbounty.github.io/ZipponDB/cli
|
||||
\\
|
||||
;
|
||||
pub const schema: []const u8 =
|
||||
\\Available commands:
|
||||
\\describe Print the schema use by the currently database.
|
||||
\\init Take the path to a schema file and initialize the database.
|
||||
\\
|
||||
\\For more informations: https://mrbounty.github.io/ZipponDB/cli
|
||||
\\
|
||||
;
|
||||
pub const no_engine: []const u8 =
|
||||
\\To start using ZipponDB you need to create a new database.
|
||||
\\This is a directory/folder that will be use to store data, logs, backup, ect.
|
||||
\\To create one use 'db new path/to/directory'. E.g. 'db new data'.
|
||||
\\Or use an existing one with 'db use'.
|
||||
\\
|
||||
\\You can also set the environment variable ZIPPONDB_PATH to the desire path.
|
||||
\\
|
||||
\\For more informations: https://mrbounty.github.io/ZipponDB/cli
|
||||
\\
|
||||
;
|
||||
pub const no_schema: []const u8 =
|
||||
\\A database was found here `{s}` but no schema find inside.
|
||||
\\To start a database, you need to attach it a schema using a schema file.
|
||||
\\By using 'schema init path/to/schema'. For more informations on how to create a schema: TODO add link
|
||||
\\
|
||||
\\You can also set the environment variable ZIPPONDB_SCHEMA to the path to a schema file.
|
||||
\\
|
||||
\\For more informations: https://mrbounty.github.io/ZipponDB/Schema
|
||||
\\
|
||||
;
|
||||
};
|
||||
+1
-1
@@ -24,7 +24,7 @@ const ConditionValue = @import("stuffs/filter.zig").ConditionValue;
|
||||
const ZipponError = @import("stuffs/errors.zig").ZipponError;
|
||||
const FileEngineError = @import("stuffs/errors.zig").FileEngineError;
|
||||
|
||||
const config = @import("config.zig");
|
||||
const config = @import("config");
|
||||
const BUFFER_SIZE = config.BUFFER_SIZE;
|
||||
const OUT_BUFFER_SIZE = config.OUT_BUFFER_SIZE;
|
||||
const MAX_FILE_SIZE = config.MAX_FILE_SIZE;
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ const ziqlParser = @import("ziqlParser.zig").Parser;
|
||||
|
||||
const ZipponError = @import("stuffs/errors.zig").ZipponError;
|
||||
|
||||
const config = @import("config.zig");
|
||||
const config = @import("config");
|
||||
const BUFFER_SIZE = config.BUFFER_SIZE;
|
||||
const CPU_CORE = config.CPU_CORE;
|
||||
const HELP_MESSAGE = config.HELP_MESSAGE;
|
||||
|
||||
@@ -16,7 +16,7 @@ const FileEngine = @import("fileEngine.zig").FileEngine;
|
||||
|
||||
// TODO: Create a schemaEngine directory and add this as core and the parser with it
|
||||
|
||||
const config = @import("config.zig");
|
||||
const config = @import("config");
|
||||
const BUFFER_SIZE = config.BUFFER_SIZE;
|
||||
|
||||
var schema_buffer: [BUFFER_SIZE]u8 = undefined;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const ZipponError = @import("errors.zig").ZipponError;
|
||||
const config = @import("config");
|
||||
|
||||
const log = std.log.scoped(.utils);
|
||||
|
||||
@@ -45,7 +46,7 @@ const stdout = std.io.getStdOut().writer();
|
||||
|
||||
// Maybe create a struct for that
|
||||
pub fn send(comptime format: []const u8, args: anytype) void {
|
||||
if (true) return;
|
||||
if (config.DONT_SEND) return;
|
||||
|
||||
stdout.print(format, args) catch |err| {
|
||||
log.err("Can't send: {any}", .{err});
|
||||
@@ -57,6 +58,7 @@ pub fn send(comptime format: []const u8, args: anytype) void {
|
||||
|
||||
/// Print an error and send it to the user pointing to the token
|
||||
pub fn printError(message: []const u8, err: ZipponError, query: ?[]const u8, start: ?usize, end: ?usize) ZipponError {
|
||||
if (config.DONT_SEND) return err;
|
||||
fa.reset();
|
||||
|
||||
var buffer = std.ArrayList(u8).init(allocator);
|
||||
|
||||
@@ -6,8 +6,8 @@ const Pool = std.Thread.Pool;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const ZipponError = @import("stuffs/errors.zig").ZipponError;
|
||||
const CPU_CORE = @import("config.zig").CPU_CORE;
|
||||
const OUT_BUFFER_SIZE = @import("config.zig").OUT_BUFFER_SIZE;
|
||||
const CPU_CORE = @import("config").CPU_CORE;
|
||||
const OUT_BUFFER_SIZE = @import("config").OUT_BUFFER_SIZE;
|
||||
const log = std.log.scoped(.thread);
|
||||
|
||||
const allocator = std.heap.page_allocator;
|
||||
|
||||
+4
-4
@@ -21,7 +21,7 @@ const printError = @import("stuffs/utils.zig").printError;
|
||||
const ZiQlParserError = @import("stuffs/errors.zig").ZiQlParserError;
|
||||
const ZipponError = @import("stuffs/errors.zig").ZipponError;
|
||||
|
||||
const PRINT_STATE = @import("config.zig").PRINT_STATE;
|
||||
const PRINT_STATE = @import("config").PRINT_STATE;
|
||||
|
||||
const log = std.log.scoped(.ziqlParser);
|
||||
|
||||
@@ -1232,7 +1232,7 @@ test "DELETE" {
|
||||
const DBEngine = @import("main.zig").DBEngine;
|
||||
|
||||
fn testParsing(source: [:0]const u8) !void {
|
||||
const TEST_DATA_DIR = @import("config.zig").TEST_DATA_DIR;
|
||||
const TEST_DATA_DIR = @import("config").TEST_DATA_DIR;
|
||||
|
||||
var db_engine = DBEngine.init(TEST_DATA_DIR, null);
|
||||
defer db_engine.deinit();
|
||||
@@ -1248,7 +1248,7 @@ fn testParsing(source: [:0]const u8) !void {
|
||||
}
|
||||
|
||||
fn expectParsingError(source: [:0]const u8, err: ZiQlParserError) !void {
|
||||
const TEST_DATA_DIR = @import("config.zig").TEST_DATA_DIR;
|
||||
const TEST_DATA_DIR = @import("config").TEST_DATA_DIR;
|
||||
|
||||
var db_engine = DBEngine.init(TEST_DATA_DIR, null);
|
||||
defer db_engine.deinit();
|
||||
@@ -1273,7 +1273,7 @@ test "Parse filter" {
|
||||
}
|
||||
|
||||
fn testParseFilter(source: [:0]const u8) !void {
|
||||
const TEST_DATA_DIR = @import("config.zig").TEST_DATA_DIR;
|
||||
const TEST_DATA_DIR = @import("config").TEST_DATA_DIR;
|
||||
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
|
||||
Reference in New Issue
Block a user