Spaces:
Running
Running
File size: 11,341 Bytes
e4bf523 | 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | 'use strict'
/**
* Copyright (c) 2017~2022, OBCon Inc.
* All rights reserved.
*/
/**
* @file
* @copyright 2017~2022, OBCon Inc.
* @author gye hyun james kim [pnuskgh@gmail.com]
*/
//--- SQL문을 사용하여 Sequelize 라이브러리를 대체하는 class
//--- 사용하지 않음
class ModelForSql {
constructor() {
this._use = true; //--- true. 사용하는 모듈
this._title = '정류기 데이터'; //--- 테이블 한글명
this._tableName = 'devicedata1s'; //--- 테이블 영문명
this._type = 'mariadb'; //--- Database type
this._conn = null; //--- Database connection
}
get tableName() {
return this._tableName;
}
get conn() {
return this._conn;
}
set conn(newValue) {
this._conn = newValue;
}
get table() {
return {
findOne: this.findOne.bind(this),
findAll: this.findAll.bind(this),
create: this.create.bind(this),
update: this.update.bind(this),
destroy: this.destroy.bind(this),
};
}
get fieldDesc() {
return {
// name: {
// type: 'string', len: 72,
// allowNull: false,
// defaultValue: '',
// validate: {},
// title: '이름',
// strType: 'string'
// },
// description: {
// type: 'text',
// allowNull: true,
// defaultValue: '',
// validate: {},
// title: '상세 설명',
// strType: 'text'
// },
// assignedUserId: {
// type: 'integer', len: 11,
// allowNull: false,
// defaultValue: 1,
// validate: {
// min: 1
// },
// title: '담당자 ID',
// strType: 'integer'
// },
// assignedUserName: {
// type: 'string', len: 72,
// allowNull: true,
// defaultValue: '',
// validate: {},
// title: '담당자',
// strType: 'string'
// },
// createdBy: {
// type: 'integer', len: 11,
// allowNull: false,
// defaultValue: 1,
// validate: {
// min: 1
// },
// title: '생성자',
// strType: 'integer'
// },
// updatedBy: {
// type: 'integer', len: 11,
// allowNull: false,
// defaultValue: 1,
// validate: {
// min: 1
// },
// title: '수정자',
// strType: 'integer'
// },
// deleted: {
// type: 'boolean',
// allowNull: false,
// defaultValue: false,
// validate: {},
// title: '삭제',
// strType: 'boolean'
// }
};
}
get fieldNames() {
return Object.getOwnPropertyNames(this.fieldDesc);
}
async findOne(sql, strQuery = null) {
//--- To-Do : 아래 코드를 수정하여 동작하도록 작성할 것
// let results = await this.findAll(sql, strQuery);
// if (0 < results.count) {
// if ((strQuery != null) && (-1 < strQuery.indexOf('NEXTVAL'))) {
// return results[0]['NEXTVAL'];
// } else {
// return results[0];
// }
// } else {
// return null;
// }
}
async findAll(sql, strQuery = null) {
//--- To-Do : 아래 코드를 수정하여 동작하도록 작성할 것
// let query = [];
// if (strQuery == null) {
// query.push('SELECT *');
// query.push(` FROM ${this._tableName}`);
// //--- WHERE 문 처리
// if (typeof(sql.where) != 'undefined') {
// query.push(' WHERE');
// query.push(this._set(sql.where, 'AND'));
// }
// //--- ORDER BY 문 처리
// if (typeof(sql.order) != 'undefined') {
// query.push(' ORDER BY');
// let data = [];
// for (let idx = 0; idx < sql.order.length; idx++) {
// let item = sql.order[idx];
// switch(item[0]) {
// case 'site': break;
// default:
// data.push(`${item[0]} ${item[1]}`);
// break;
// }
// }
// query.push(data.join(', '));
// }
// //--- LIMIT 문 처리
// if (typeof(sql.limit) != 'undefined') {
// query.push(` LIMIT ${sql.limit}`);
// }
// query = query.join(' ');
// } else {
// query = strQuery;
// }
// logger.info(query);
// let results = await db.conn.query(query);
// if (config.databases.obcon.type == 'Tibero') {
// for (let idx = 0; idx < results.length; idx++) {
// for (let pos = 0; pos < this._fieldNames.length; pos++) {
// let fieldName = this._fieldNames[pos];
// if (typeof(results[idx][fieldName.toUpperCase()]) != 'undefined') {
// results[idx][fieldName] = results[idx][fieldName.toUpperCase()];
// }
// }
// }
// }
// return results;
}
_set(item, delimiter, isIn=false) {
//--- To-Do : 아래 코드를 수정하여 동작하도록 작성할 것
// let data = [];
// for (const [key, value] of Object.entries(item)) {
// if (isIn) {
// // let key1 = (config.databases.obcon.type == 'Tibero') ? key.toUpperCase():key;
// if (this._fieldNames.includes(key) == false) {
// continue;
// }
// }
// switch(key) {
// case 'site': break;
// default:
// switch(typeof(value)) {
// case 'string':
// data.push(`${key} = '${value}'`);
// break;
// case 'number':
// case 'boolean':
// default:
// data.push(`${key} = ${value}`);
// break;
// }
// break;
// }
// }
// return data.join(` ${delimiter} `);
}
async create(item, strQuery = null) {
//--- To-Do : 아래 코드를 수정하여 동작하도록 작성할 것
// let query = `SELECT seq_${this._tableName}.NEXTVAL FROM DUAL`.replace('OBICON.', '');
// let id = await this.findOne(null, query);
// item['id'] = id;
// query = [];
// if (strQuery == null) {
// query.push(`INSERT INTO ${this._tableName} (`);
// let data = [];
// for (const [key, value] of Object.entries(item)) {
// // let key1 = (config.databases.obcon.type == 'Tibero') ? key.toUpperCase():key;
// if (this._fieldNames.includes(key)) {
// data.push(key);
// }
// }
// query.push(data.join(', '));
// query.push(') VALUES (');
// data = [];
// for (const [key, value] of Object.entries(item)) {
// // let key1 = (config.databases.obcon.type == 'Tibero') ? key.toUpperCase():key;
// if (this._fieldNames.includes(key)) {
// switch(key) {
// case 'site': break;
// default:
// switch(typeof(value)) {
// case 'string':
// data.push(`'${value}'`);
// break;
// case 'number':
// case 'boolean':
// default:
// data.push(`${value}`);
// break;
// }
// break;
// }
// }
// }
// query.push(data.join(', '));
// query.push(')');
// query = query.join(' ');
// } else {
// query = strQuery;
// }
// logger.info(`SQL Create : ${query}`);
// let results = await db.conn.query(query);
// results[0] = results.count;
// return results;
}
async update(item, sql = null, strQuery = null) {
//--- To-Do : 아래 코드를 수정하여 동작하도록 작성할 것
// let query = [];
// if (strQuery == null) {
// query.push(`UPDATE ${this._tableName}`);
// query.push(' SET');
// query.push(this._set(item, ',', true));
// //--- WHERE 문 처리
// if (typeof(sql.where) != 'undefined') {
// query.push(' WHERE');
// query.push(this._set(sql.where, 'AND'));
// }
// query = query.join(' ');
// } else {
// query = strQuery;
// }
// logger.info(`SQL Update : ${query}`);
// let results = await db.conn.query(query);
// results[0] = results.count;
// return results;
}
async destroy(sql, strQuery = null) {
//--- To-Do : 아래 코드를 수정하여 동작하도록 작성할 것
// let query = [];
// if (strQuery == null) {
// query.push(`DELETE FROM ${this._tableName}`);
// //--- WHERE 문 처리
// if (typeof(sql.where) != 'undefined') {
// query.push(' WHERE');
// query.push(this._set(sql.where, 'AND'));
// }
// query = query.join(' ');
// } else {
// query = strQuery;
// }
// //--- To-Do : ppp, 테스트 필요
// logger.info(`SQL delete : ${query}`);
// if (-1 < query.indexOf('id = ')) {
// let results = await db.conn.query(query);
// results[0] = results.count;
// return results;
// }
// return 0;
}
//--- 데이터 초기화
init() {
}
}
module.exports = ModelForSql;
|