Commit 146d0596 authored by Lakr Aream's avatar Lakr Aream 👼🏽

启用数据库!

parent 761c1ee6
......@@ -154,6 +154,17 @@ echo $signStr;
- Actions: create, delete, modify.element, list, info
- User type: root(unique), admin, developer, user
```
SQL TABLE CONTENT
----------users----------
id: int(11), not null, auto_increment,
name: string 255 char long
icon: string, 20000 char long base64encoded
-------------------------
```
<details>
<summary>Create User</summary>
......
......@@ -15,8 +15,8 @@ app:
# Database Config For Backend Application
database:
host: "127.0.0.1" # database host name
port: 3306 # database port
host: "iomun.cn" # database host name
port: 15092 # database port
user: "root" # database user name
base: "Candiay" # database name
pass: "00000000" # database password for your user
\ No newline at end of file
......@@ -16,6 +16,7 @@
},
"scripts": {
"build": "tsc",
"config": "cp ./config/config.yml /etc/Candiay/coreBackend/config/config.yml",
"start": "tsc && node dist/main.js",
"docker": "cd docker && ./start.sh"
},
......
......@@ -17,21 +17,21 @@ export class ConfigManager {
public requireSign: boolean
constructor() {
console.log("ConfigManager constructor");
this.location = "/etc/Candiay/coreBackend/config/config.yml";
this.object = yaml.parse(fs.readFileSync(this.location).toString());
this.portToBind = this.object.app.port;
this.rootTicket = this.object.app.root;
console.log("ConfigManager constructor")
this.location = "/etc/Candiay/coreBackend/config/config.yml"
this.object = yaml.parse(fs.readFileSync(this.location).toString())
this.portToBind = this.object.app.port
this.rootTicket = this.object.app.root
if (this.rootTicket === "00000") {
this.rootTicket = null;
this.rootTicket = null
}
this.accpetAddr = this.object.app.accpet;
this.requireSign = this.object.app.use_development_ticket;
this.accpetAddr = this.object.app.accpet
this.requireSign = this.object.app.use_development_ticket
}
healthCheck() {
console.log("ConfigManager dummy init");
console.log(this.object);
console.log("ConfigManager dummy init")
console.log(this.object)
}
}
\ No newline at end of file
......@@ -15,35 +15,74 @@ export class DataBase {
private connection: any
constructor() {
console.log("DataBase constructor");
const object = ConfigManager.shared.object;
this.host = object.database.host;
this.port = object.database.port;
this.user = object.database.user;
this.pass = object.database.pass;
this.base = object.database.base;
const uuu = String(this.host + ":" + String(this.port));
this.url = uuu;
console.log("DataBase constructor")
const object = ConfigManager.shared.object
this.host = object.database.host
this.port = object.database.port
this.user = object.database.user
this.pass = object.database.pass
this.base = object.database.base
const uuu = String(this.host + ":" + String(this.port))
this.url = uuu
this.connection = mysql.createConnection({
host : this.host,
user : this.user,
password : this.pass,
database : this.base,
});
})
}
healthCheck() {
console.log("ConfigManager dummy init");
console.log("DataBase Inf - host " + this.host + "");
console.log("DataBase Inf - port " + this.port + "");
console.log("DataBase Inf - user " + this.user + "");
console.log("DataBase Inf - pass " + this.pass + "");
console.log("DataBase Inf - base " + this.base + "");
console.log("DataBase Inf - url " + this.url + "");
console.log("ConfigManager dummy init")
console.log("DataBase Inf - host " + this.host + "")
console.log("DataBase Inf - port " + this.port + "")
console.log("DataBase Inf - user " + this.user + "")
console.log("DataBase Inf - pass " + this.pass + "")
console.log("DataBase Inf - base " + this.base + "")
console.log("DataBase Inf - url " + this.url + "")
}
connect() {
this.connection.connect()
this.createTableIfNotExists()
}
createTableIfNotExists() {
let cmd = "CREATE TABLE IF NOT EXISTS `Candiay`.`users` (" + "\n"
cmd += " `name` varchar(255) NOT NULL," + "\n"
cmd += " `pass` varchar(255) NULL," + "\n"
cmd += " `token` varchar(255) NULL," + "\n"
cmd += " `guard` date NULL," + "\n"
cmd += " `actived` int(1) NULL DEFAULT 1," + "\n"
cmd += " `info` json NULL," + "\n"
cmd += " PRIMARY KEY (`name`)" + "\n"
cmd += ");" + "\n"
/*
CREATE TABLE `Candiay`.`users` (
`name` varchar(255) NOT NULL,
`pass` varchar(255) NULL,
`token` varchar(255) NULL,
`guard` date NULL,
`actived` int(1) NULL DEFAULT 1,
`info` json NULL,
PRIMARY KEY (`name`)
);
*/
this.connection.query(cmd, (err, result) => {
if(err){
console.log('[SQL ERROR] - ',err.message)
}
console.log('--------------------------SQL----------------------------')
console.log(result)
console.log('---------------------------------------------------------')
})
}
queryAllObjects(fromTable: string) {
}
}
\ No newline at end of file
......@@ -11,13 +11,13 @@ const port = ConfigManager.shared.portToBind
// Register enterpoints
coreApp.get("/", (req, res) => {
res.send("Candiay Core");
res.send("Candiay Core")
})
// Start servers
coreApp.listen(port, err => {
if (err) {
return console.error(err);
return console.error(err)
}
return console.log("[coreApp] Starting services at: " + String(port));
return console.log("[coreApp] Starting services at: " + String(port))
})
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment