1 module konnexengine.db.devdb;
2 
3 import std.uuid: UUID, sha1UUID;
4 import std.conv: to;
5 import std.typecons: Nullable, nullable;
6 
7 import vibe.core.log: logInfo;
8 import konnexengine.db.functions;
9 import konnexengine.db.schema.user: User;
10 
11 /// DevDB `struct`
12 struct DevDB
13 {
14 	/// generateDevDB() `function`
15 	User[] generateUsers()
16 	{
17 		import std.conv: to;
18 		
19 		User[] devDB = [];
20 		
21 		for(uint i=0; i<10; i++)
22 		{
23 			auto user = User(sha1UUID("user"~i.to!string~"@email.com", sha1UUID("konnex-engine.com")).nullable);
24 			user.email ~= sha1UUID("user"~i.to!string~"@email.com", sha1UUID("konnex-engine.com")).nullable;
25 			user.username = "user"~i.to!string~"@email.com";
26 			user.password = "password"~i.to!string;
27 
28 			devDB ~= user;
29 			logInfo(user.to!string);
30 		}
31 		return devDB;
32 	}
33 	///
34 	unittest {
35 		import std.uuid: UUID, sha1UUID;
36 		import std.typecons: nullable;
37 		auto devDB = DB(DevDB());
38 		auto db = devDB.generateUsers();
39 		logInfo(db[0].id.to!string);
40 		assert(is(typeof(db) == User[]));
41 		assert(is(typeof(db[0].id) == Nullable!UUID));
42 		assert(is(typeof(db[0].email) == Nullable!UUID[]));
43 		assert(is(typeof(db[0].username) == Nullable!string));
44 		assert(is(typeof(db[0].password) == Nullable!string));
45 		auto a = sha1UUID("user0@email.com", sha1UUID("konnex-engine.com"));
46 		auto aa = a.nullable;
47 		assert(db[0].id == a);
48 		auto b = sha1UUID("user0@email.com", sha1UUID("konnex-engine.com")).nullable;
49 		assert(db[0].email == [b]);
50 		assert(db[0].username == "user0@email.com");
51 		assert(db[0].password == "password0");
52 	}
53 
54 	/// flushToDisk() `function`
55 	void flushToDisk(){
56 		import std.file: write;
57 	}
58 	///
59 	unittest {
60 		// TODO: implement test
61 		auto dbutils = DevDB();
62 		auto devDB = dbutils.generateUsers();
63 		assert(is(typeof(devDB) == User[]));
64 	}
65 }
66