From 635f16f8ff5f1dd5780be1ea799d267bb5cf9227 Mon Sep 17 00:00:00 2001 From: Overlord Date: Wed, 26 Nov 2025 12:29:31 +0100 Subject: [PATCH] fuckass db shit --- app/src/database/db.v | 56 ++++++++++++++++++++++++++------------- app/src/database/tables.v | 22 +++++++++++++++ app/src/main.v | 5 ++++ 3 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 app/src/database/tables.v diff --git a/app/src/database/db.v b/app/src/database/db.v index 5fa8c2e..69b442c 100644 --- a/app/src/database/db.v +++ b/app/src/database/db.v @@ -1,7 +1,9 @@ module database -import fleximus.argon2 import rand +// import db.mysql +import db.redis +import fleximus.argon2 pub struct Crypto {} @@ -15,24 +17,42 @@ pub fn Crypto.hash_verify(password string, hash string) !bool { return argon2.verify(hash, password.bytes()) or { return error('argon2 verify failed: ${err}') } } -// db structure +// struct Database { +// mut: +// conn mysql.DB +// } // -// users -// CREATE TABLE users ( -// id SERIAL PRIMARY KEY, -// name TEXT UNIQUE NOT NULL, -// password_hash TEXT NOT NULL -// ); +// pub fn get_connection(cfg util.Config) !&Database { +// // connection := mysql.connect(mysql.Config{ +// // host: cfg.database.host +// // // port: u32(cfg.database.port) +// // dbname: 'CDN_DATABASE' +// // username: cfg.database.username +// // password: cfg.database.password +// // })! // -// logins -// CREATE TABLE login_attempts ( -// id SERIAL PRIMARY KEY, -// username TEXT NOT NULL, -// ip TEXT NOT NULL, -// success BOOLEAN NOT NULL, -// attempt_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -// ); -// -// files +// //return &Database{ conn: connection } +// return &Database{} +// } // +// pub fn (mut db Database) query[T](query_fn fn(conn &mysql.Connection) ![]T) ![]T { +// result := query_fn(db.conn) or { +// // Connection died, reconnect +// db.conn = mysql.connect(db.config)! +// return query_fn(db.conn)! +// } +// return result +// } // +// pub fn Database.test() {} + +pub fn test() ! { + mut r := redis.connect(redis.Config{ + host: 'vpn.security-command.org' + port: 6767 + password: 'SuperSecretPassword123' + })! + + pong := r.ping() or { panic(err) } + println(pong) +} diff --git a/app/src/database/tables.v b/app/src/database/tables.v new file mode 100644 index 0000000..ddb0781 --- /dev/null +++ b/app/src/database/tables.v @@ -0,0 +1,22 @@ +module database + +@[table: 'users'] +struct Users { + id int @[primary; serial] + name string @[nonnull; unique] + password_hash string @[nonnull] +} + +@[table: 'login_attempts'] +struct Logins { + ip string @[primary] + attempts int @[nonnull] + attempt_time string @[default: 'CURRENT_TIMESTAMP'; nonnull] +} + +@[table: 'files'] +struct Files { + id int @[primary; serial] + path string @[nonnull; unique] + visible bool @[default: false; nonnull] +} diff --git a/app/src/main.v b/app/src/main.v index d2bde07..4bf01d6 100644 --- a/app/src/main.v +++ b/app/src/main.v @@ -3,6 +3,7 @@ module main import os import veb import util +import database import thomaspeissl.dotenv // @@ -142,6 +143,10 @@ fn main() { app: &app } + database.test()! + + // db := database.get_connection(app.cfg)! + app.register_controller[Auth, Context]('/auth', mut auth)! app.enable_static_compression = true