Subversion Repositories MLServ

Rev

Rev 1 | Rev 7 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 5
Line 1... Line 1...
1
/* $Id: db.c 1 2024-09-07 01:58:02Z nishi $ */
1
/* $Id: db.c 5 2024-09-25 00:19:35Z nishi $ */
-
 
2
 
-
 
3
#include "cm_db.h"
-
 
4
 
-
 
5
#include <sqlite3.h>
-
 
6
 
-
 
7
#include <stddef.h>
-
 
8
 
-
 
9
sqlite3* cm_db_init(void) {
-
 
10
	int ret;
-
 
11
	sqlite3* sql;
-
 
12
	ret = sqlite3_open(DB_PATH, &sql);
-
 
13
	if(ret != SQLITE_OK) {
-
 
14
		return NULL;
-
 
15
	}
-
 
16
	ret = sqlite3_exec(sql, "create table if not exists lists(name text, description text)", NULL, NULL, NULL);
-
 
17
	if(ret != SQLITE_OK) {
-
 
18
		sqlite3_close(sql);
-
 
19
		return NULL;
-
 
20
	}
-
 
21
	ret = sqlite3_exec(sql, "create table if not exists users(email text, password text)", NULL, NULL, NULL);
-
 
22
	if(ret != SQLITE_OK) {
-
 
23
		sqlite3_close(sql);
-
 
24
		return NULL;
-
 
25
	}
-
 
26
	ret = sqlite3_exec(sql, "create table if not exists tokens(list text, email text, token text, expire numeric)", NULL, NULL, NULL);
-
 
27
	if(ret != SQLITE_OK) {
-
 
28
		sqlite3_close(sql);
-
 
29
		return NULL;
-
 
30
	}
-
 
31
	return sql;
-
 
32
}