mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Authetication, logger middleware, db create tool
This commit is contained in:
parent
5f0b17a0db
commit
ebd27f93c1
11 changed files with 164 additions and 94 deletions
39
utils/dbSetup.js
Normal file
39
utils/dbSetup.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
const utils = require('../utils/utils.js')
|
||||
const dbtools = require('../utils/dbtools.js')
|
||||
const dbStructPath = '../modules/api/apiDBStruct.json'
|
||||
const usersDBPath = '../data/dbs/users.db'
|
||||
|
||||
let authDB
|
||||
|
||||
console.clear()
|
||||
|
||||
function CreateDB () {
|
||||
const dbStruct = utils.ReadJSON(dbStructPath)
|
||||
authDB = dbtools.GetDB(usersDBPath)
|
||||
|
||||
Object.keys(dbStruct).forEach((tableName) => {
|
||||
const tableData = dbStruct[tableName]
|
||||
dbtools.CreateTable(authDB, tableName, tableData.tableStruct, tableData.foreignKey)
|
||||
})
|
||||
|
||||
try {
|
||||
// TODO: fill with data
|
||||
dbtools.Insert(authDB, 'users', {
|
||||
pw: 2,
|
||||
notes: 'hemnlo'
|
||||
})
|
||||
dbtools.Insert(authDB, 'users', {
|
||||
pw: 1,
|
||||
notes: 'hemnlo'
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
// Object.keys(dbStruct).forEach((key) => {
|
||||
// console.log(key)
|
||||
// console.log(dbtools.TableInfo(authDB, key))
|
||||
// })
|
||||
}
|
||||
CreateDB()
|
Loading…
Add table
Add a link
Reference in a new issue