-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
37 lines (32 loc) · 1008 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const sqlite3 = require('sqlite3').verbose();
const path = require('path');
const dbPath = path.join(__dirname, 'scim.db');
const db = new sqlite3.Database(dbPath);
// Initialize tables for users, groups, and group memberships
db.serialize(() => {
db.run(`
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
userName TEXT NOT NULL,
json_body text NOT NULL,
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
db.run(`
CREATE TABLE IF NOT EXISTS groups (
id TEXT PRIMARY KEY,
displayName TEXT NOT NULL,
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
db.run(`
CREATE TABLE IF NOT EXISTS group_memberships (
groupId TEXT,
userId TEXT,
FOREIGN KEY(groupId) REFERENCES groups(id),
FOREIGN KEY(userId) REFERENCES users(id),
PRIMARY KEY (groupId, userId)
)
`);
});
module.exports = db;