Former-commit-id: df02243ee1a46d640ad5ecf4ddd276715a42714a
This commit is contained in:
Ben
2022-02-07 17:47:51 +00:00
parent e4fcd35317
commit 24e96c0eb6
5 changed files with 75 additions and 0 deletions

BIN
README.md

Binary file not shown.

View File

@@ -0,0 +1,29 @@
const DataTypes = require('./types.js');
class PSQLObjectRelation {
constructor(psqlConnection) {
this.connection = psqlConnection;
}
async AddModel(name, model) {
Logger.database(`ORM Adding ${name}`);
let sql = `CREATE TABLE IF NOT EXISTS ${name} (`;
let keys = Object.keys(model);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
let value = model[key];
sql += `${key} ${value}`;
if (i < keys.length - 1) sql += ', ';
}
sql += ');';
Logger.database(sql);
await this.connection.query(sql);
}
async SyncModels() {
Logger.database('ORM Syncing...');
}
}
module.exports = PSQLObjectRelation;

View File

@@ -0,0 +1,19 @@
class RelationshipTypes {
static get UNIQUE() {
return 'UNIQUE';
}
static get NOT_NULL() {
return 'NOT NULL';
}
static get REFERENCES() {
return 'REFERENCES';
}
static FOREIGN_KEY(localKey, foreignKey) {
return `FOREIGN KEY (${localKey}) REFERENCES ${foreignKey}`;
}
}
module.exports = DataTypes;

View File

@@ -0,0 +1,27 @@
class DataTypes {
static VARCHAR(length) {
return `VARCHAR(${length})`;
}
static get INTEGER() {
return 'INT';
}
static get BIGINT() {
return 'BIGINT';
}
static get TEXT() {
return 'TEXT';
}
static get BOOLEAN() {
return 'BOOLEAN';
}
static get TIMESTAMP() {
return 'TIMESTAMP WITHOUT TIME ZONE';
}
}
module.exports = DataTypes;