@giorgi-g/csv-parser
Version:
CSV parser for migrations with Sequelizer
107 lines (106 loc) • 5.48 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DB = exports.Sequelizer = void 0;
const sequelize_1 = require("sequelize");
const { DB_CONNECTION_STRING, DB_ENV, DB_PASSWORD, DB_PORT, DB_USER, } = require("../../config");
const { Sequelize } = require("sequelize");
const Sequelizer = (schema) => (new Sequelize(DB_CONNECTION_STRING != null
? DB_CONNECTION_STRING : `postgres://${DB_USER}:${DB_PASSWORD}@pgsql.${DB_ENV}.frx:${DB_PORT}/${schema}`));
exports.Sequelizer = Sequelizer;
class DB {
constructor(schema, logging = false) {
this.logging = false;
this.select = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.SELECT,
logging: logging != null ? logging : this.logging
});
});
this.insert = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.INSERT,
logging: logging != null ? logging : this.logging
});
});
this.update = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.UPDATE,
logging: logging != null ? logging : this.logging
});
});
this.bulkUpdate = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.BULKUPDATE,
logging: logging != null ? logging : this.logging
});
});
this.bulkDelete = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.BULKDELETE,
logging: logging != null ? logging : this.logging
});
});
this.delete = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.DELETE,
logging: logging != null ? logging : this.logging
});
});
this.upsert = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.UPSERT,
logging: logging != null ? logging : this.logging
});
});
this.version = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.VERSION,
logging: logging != null ? logging : this.logging
});
});
this.showTables = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.SHOWTABLES,
logging: logging != null ? logging : this.logging
});
});
this.showIndexes = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.SHOWINDEXES,
logging: logging != null ? logging : this.logging
});
});
this.describe = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.DESCRIBE,
logging: logging != null ? logging : this.logging
});
});
this.raw = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.RAW,
logging: logging != null ? logging : this.logging
});
});
this.foreignKeys = (query, logging = null) => __awaiter(this, void 0, void 0, function* () {
return yield this.sequelizer.query(query, {
type: sequelize_1.QueryTypes.FOREIGNKEYS,
logging: logging != null ? logging : this.logging
});
});
this.logging = logging;
this.sequelizer = new Sequelize(DB_CONNECTION_STRING != null
? DB_CONNECTION_STRING
: `postgres://${DB_USER}:${DB_PASSWORD}@pgsql.${DB_ENV}.frx:${DB_PORT}/${schema}`);
}
}
exports.DB = DB;