Comparing version 0.14.0 to 0.14.1
@@ -51,3 +51,3 @@ "use strict"; | ||
async connect(settings) { | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -61,3 +61,3 @@ /** | ||
async getSchemas() { | ||
return { tables: {} }; | ||
return Promise.resolve({ tables: {} }); | ||
} | ||
@@ -71,3 +71,3 @@ /** | ||
async createTable(model) { | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -80,3 +80,3 @@ /** Adds a column to a table | ||
async addColumn(model, column_property) { | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -89,3 +89,3 @@ /** Creates an index. | ||
async createIndex(model_name, index) { | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -98,3 +98,3 @@ /** Creates a foreign key. | ||
async createForeignKey(model, column, type, references) { | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -108,3 +108,3 @@ /** | ||
async drop(model) { | ||
throw new Error('not implemented'); | ||
return Promise.reject(new Error('not implemented')); | ||
} | ||
@@ -209,3 +209,2 @@ /** @internal */ | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const field in group_fields) { | ||
@@ -212,0 +211,0 @@ const expr = group_fields[field]; |
"use strict"; | ||
// tslint:disable:max-classes-per-file | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -16,3 +15,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
try { | ||
// tslint:disable-next-line:no-var-requires | ||
mongodb = require('mongodb'); | ||
@@ -25,4 +23,4 @@ } | ||
} | ||
const stream_1 = __importDefault(require("stream")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const stream_1 = __importDefault(require("stream")); | ||
const types = __importStar(require("../types")); | ||
@@ -70,3 +68,3 @@ const base_1 = require("./base"); | ||
case '$gte': | ||
case '$lte': | ||
case '$lte': { | ||
let sub_value = value[sub_key]; | ||
@@ -87,2 +85,3 @@ if (is_objectid) { | ||
return lodash_1.default.zipObject([key], [value]); | ||
} | ||
case '$contains': | ||
@@ -185,5 +184,3 @@ if (Array.isArray(value[sub_key])) { | ||
}, 0); | ||
subs.unshift({}); | ||
const obj = lodash_1.default.extend.apply(lodash_1.default, subs); | ||
subs.shift(); | ||
const obj = lodash_1.default.extend({}, ...subs); | ||
const keys = Object.keys(obj); | ||
@@ -227,3 +224,2 @@ const after_count = keys.length; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const field in group_fields) { | ||
@@ -244,3 +240,3 @@ const expr = group_fields[field]; | ||
else { | ||
return MongoDBAdapter.wrapError('unknown error', error); | ||
return base_1.AdapterBase.wrapError('unknown error', error); | ||
} | ||
@@ -296,3 +292,2 @@ } | ||
const indexes = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in schema) { | ||
@@ -397,4 +392,4 @@ const property = schema[column]; | ||
} | ||
catch (error) { | ||
throw _processSaveError(error); | ||
catch (e) { | ||
throw _processSaveError(e); | ||
} | ||
@@ -472,3 +467,2 @@ let error; | ||
}; | ||
// tslint:disable-next-line:forin | ||
for (const key in conditions) { | ||
@@ -769,3 +763,3 @@ const value = conditions[key]; | ||
async _getSchema(table) { | ||
return 'NO SCHEMA'; | ||
return Promise.resolve('NO SCHEMA'); | ||
} | ||
@@ -783,3 +777,2 @@ /** @internal */ | ||
_buildUpdateOps(schema, update_ops, data, path, object) { | ||
// tslint:disable-next-line:forin | ||
for (const column in object) { | ||
@@ -786,0 +779,0 @@ const value = object[column]; |
@@ -13,3 +13,3 @@ export interface IAdapterSettingsMySQL { | ||
use_master_for_read?: boolean; | ||
read_replicas: { | ||
read_replicas: Array<{ | ||
host?: string; | ||
@@ -20,3 +20,3 @@ port?: number; | ||
pool_size?: number; | ||
}[]; | ||
}>; | ||
}; | ||
@@ -23,0 +23,0 @@ } |
@@ -15,3 +15,2 @@ "use strict"; | ||
try { | ||
// tslint:disable-next-line:no-var-requires | ||
mysql = require('mysql'); | ||
@@ -22,6 +21,7 @@ } | ||
} | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const stream_1 = __importDefault(require("stream")); | ||
const util_1 = __importDefault(require("util")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const types = __importStar(require("../types")); | ||
const base_1 = require("./base"); | ||
const sql_base_1 = require("./sql_base"); | ||
@@ -82,3 +82,3 @@ function _typeToSQL(property, support_fractional_seconds) { | ||
else { | ||
return MySQLAdapter.wrapError('unknown error', error); | ||
return base_1.AdapterBase.wrapError('unknown error', error); | ||
} | ||
@@ -159,3 +159,2 @@ } | ||
const column_sqls = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in model_class._schema) { | ||
@@ -202,3 +201,2 @@ const property = model_class._schema[column]; | ||
const columns = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in index.columns) { | ||
@@ -321,8 +319,3 @@ const order = index.columns[column]; | ||
if (conditions.length > 0) { | ||
try { | ||
sql += ' WHERE ' + this._buildWhere(this._connection.models[model]._schema, conditions, values); | ||
} | ||
catch (error) { | ||
throw error; | ||
} | ||
sql += ' WHERE ' + this._buildWhere(this._connection.models[model]._schema, conditions, values); | ||
} | ||
@@ -345,3 +338,2 @@ let result; | ||
const insert_data = {}; | ||
// tslint:disable-next-line:forin | ||
for (const key in data) { | ||
@@ -357,3 +349,2 @@ const value = data[key]; | ||
for (const condition of conditions) { | ||
// tslint:disable-next-line:forin | ||
for (const key in condition) { | ||
@@ -366,3 +357,3 @@ const value = condition[key]; | ||
let fields; | ||
let places; | ||
let places = ''; | ||
[fields, places] = this._buildUpdateSet(model, insert_data, values, true); | ||
@@ -597,2 +588,3 @@ let sql = `INSERT INTO \`${table_name}\` (${fields}) VALUES (${places})`; | ||
adapter_connection.release(); | ||
return Promise.resolve(); | ||
} | ||
@@ -798,3 +790,2 @@ /** @internal */ | ||
const places = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in schema) { | ||
@@ -814,3 +805,2 @@ const property = schema[column]; | ||
const places = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in data) { | ||
@@ -897,9 +887,9 @@ const value = data[column]; | ||
} | ||
catch (error) { | ||
if (error.code === 'ER_BAD_DB_ERROR') { | ||
catch (error1) { | ||
if (error1.code === 'ER_BAD_DB_ERROR') { | ||
try { | ||
await client.queryAsync(`CREATE DATABASE \`${this._database}\``); | ||
} | ||
catch (error) { | ||
throw MySQLAdapter.wrapError('unknown error', error); | ||
catch (error2) { | ||
throw MySQLAdapter.wrapError('unknown error', error2); | ||
} | ||
@@ -909,6 +899,6 @@ return (await this._createDatabase(client)); | ||
else { | ||
const msg = error.code === 'ER_DBACCESS_DENIED_ERROR' | ||
const msg = error1.code === 'ER_DBACCESS_DENIED_ERROR' | ||
? `no access right to the database '${this._database}'` | ||
: 'unknown error'; | ||
throw MySQLAdapter.wrapError(msg, error); | ||
throw MySQLAdapter.wrapError(msg, error1); | ||
} | ||
@@ -915,0 +905,0 @@ } |
@@ -14,6 +14,4 @@ "use strict"; | ||
let pg; | ||
// tslint:disable-next-line:variable-name | ||
let QueryStream; | ||
try { | ||
// tslint:disable-next-line:no-var-requires | ||
pg = require('pg'); | ||
@@ -25,9 +23,9 @@ } | ||
try { | ||
// tslint:disable-next-line:no-var-requires | ||
QueryStream = require('pg-query-stream'); | ||
} | ||
catch (error) { /**/ } | ||
const stream_1 = __importDefault(require("stream")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const stream_1 = __importDefault(require("stream")); | ||
const types = __importStar(require("../types")); | ||
const base_1 = require("./base"); | ||
const sql_base_1 = require("./sql_base"); | ||
@@ -75,6 +73,6 @@ function _typeToSQL(property) { | ||
let column = ''; | ||
let key = error.message.match(/unique constraint \"(.*)\"/); | ||
let key = error.message.match(/unique constraint "(.*)"/); | ||
if (key != null) { | ||
column = key[1]; | ||
key = column.match(new RegExp(`${table_name}_([^']*)_key`)); | ||
key = new RegExp(`${table_name}_([^']*)_key`).exec(column); | ||
if (key != null) { | ||
@@ -88,3 +86,3 @@ column = key[1]; | ||
else { | ||
return PostgreSQLAdapter.wrapError('unknown error', error); | ||
return base_1.AdapterBase.wrapError('unknown error', error); | ||
} | ||
@@ -137,3 +135,2 @@ } | ||
const column_sqls = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in model_class._schema) { | ||
@@ -178,3 +175,2 @@ const property = model_class._schema[column]; | ||
const columns = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in index.columns) { | ||
@@ -297,8 +293,3 @@ const order = index.columns[column]; | ||
if (conditions.length > 0) { | ||
try { | ||
sql += ' WHERE ' + this._buildWhere(this._connection.models[model]._schema, conditions, values); | ||
} | ||
catch (error) { | ||
throw error; | ||
} | ||
sql += ' WHERE ' + this._buildWhere(this._connection.models[model]._schema, conditions, values); | ||
} | ||
@@ -485,2 +476,3 @@ let result; | ||
adapter_connection.release(); | ||
return Promise.resolve(); | ||
} | ||
@@ -664,3 +656,2 @@ /** @internal */ | ||
const places = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in schema) { | ||
@@ -680,3 +671,2 @@ const property = schema[column]; | ||
const places = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in data) { | ||
@@ -683,0 +673,0 @@ const value = data[column]; |
@@ -15,3 +15,2 @@ "use strict"; | ||
try { | ||
// tslint:disable-next-line:no-var-requires | ||
redis = require('redis'); | ||
@@ -22,4 +21,4 @@ } | ||
} | ||
const util_1 = __importDefault(require("util")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const util_1 = __importDefault(require("util")); | ||
const types = __importStar(require("../types")); | ||
@@ -150,3 +149,3 @@ const inflector_1 = require("../util/inflector"); | ||
async upsert(model, data, conditions, options) { | ||
throw new Error('not implemented'); | ||
return Promise.reject(new Error('not implemented')); | ||
} | ||
@@ -192,3 +191,3 @@ /** @internal */ | ||
async count(model, conditions, options) { | ||
throw new Error('not implemented'); | ||
return Promise.reject(new Error('not implemented')); | ||
} | ||
@@ -195,0 +194,0 @@ /** @internal */ |
@@ -39,3 +39,2 @@ "use strict"; | ||
const insert_data = {}; | ||
// tslint:disable-next-line:forin | ||
for (const key in data) { | ||
@@ -51,3 +50,2 @@ const value = data[key]; | ||
for (const condition of conditions) { | ||
// tslint:disable-next-line:forin | ||
for (const key in condition) { | ||
@@ -85,3 +83,2 @@ const value = condition[key]; | ||
value = Number(value); | ||
// tslint:disable-next-line:no-bitwise | ||
if (isNaN(value) || (value >> 0) !== value) { | ||
@@ -327,3 +324,2 @@ value = -2147483648; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const field in group_fields) { | ||
@@ -330,0 +326,0 @@ const expr = group_fields[field]; |
@@ -15,3 +15,2 @@ "use strict"; | ||
try { | ||
// tslint:disable-next-line:no-var-requires | ||
sqlite3 = require('sqlite3'); | ||
@@ -22,6 +21,7 @@ } | ||
} | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const stream_1 = __importDefault(require("stream")); | ||
const util_1 = __importDefault(require("util")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const types = __importStar(require("../types")); | ||
const base_1 = require("./base"); | ||
const sql_base_1 = require("./sql_base"); | ||
@@ -69,3 +69,3 @@ function _typeToSQL(property) { | ||
else { | ||
return SQLite3Adapter.wrapError('unknown error', error); | ||
return base_1.AdapterBase.wrapError('unknown error', error); | ||
} | ||
@@ -111,3 +111,2 @@ } | ||
const column_sqls = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in model_class._schema) { | ||
@@ -164,3 +163,2 @@ const property = model_class._schema[column]; | ||
const columns = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in index.columns) { | ||
@@ -461,2 +459,3 @@ const order = index.columns[column]; | ||
adapter_connection.close(); | ||
return Promise.resolve(); | ||
} | ||
@@ -479,3 +478,3 @@ /** @internal */ | ||
run(sql, ...params) { | ||
return this._client.run.apply(this._client, arguments); | ||
return this._client.run(sql, ...params); | ||
} | ||
@@ -486,3 +485,3 @@ /** | ||
all(sql, ...params) { | ||
return this._client.all.apply(this._client, arguments); | ||
return this._client.all(sql, ...params); | ||
} | ||
@@ -600,3 +599,2 @@ /** @internal */ | ||
const places = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in schema) { | ||
@@ -616,3 +614,2 @@ const property = schema[column]; | ||
const places = []; | ||
// tslint:disable-next-line:forin | ||
for (const column in data) { | ||
@@ -619,0 +616,0 @@ const value = data[column]; |
@@ -22,3 +22,3 @@ "use strict"; | ||
try { | ||
// tslint:disable-next-line:variable-name | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const CommandClass = require(path_1.default.resolve(__dirname, '..', 'command', command)); | ||
@@ -25,0 +25,0 @@ const runner = new CommandClass(argv); |
@@ -60,3 +60,3 @@ /// <reference types="node" /> | ||
create(data?: ModelValueObject<M>): Promise<M>; | ||
createBulk(data?: ModelValueObject<M>[]): Promise<M[]>; | ||
createBulk(data?: Array<ModelValueObject<M>>): Promise<M[]>; | ||
count(condition?: object): Promise<number>; | ||
@@ -63,0 +63,0 @@ update(updates: any, condition?: object): Promise<number>; |
"use strict"; | ||
// tslint:disable:max-classes-per-file | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -16,6 +15,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const events_1 = require("events"); | ||
const util_1 = require("util"); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const util_1 = require("util"); | ||
// tslint:disable-next-line:no-var-requires variable-name | ||
const Toposort = require('toposort-class'); | ||
const mongodb_1 = require("../adapters/mongodb"); | ||
@@ -30,4 +27,5 @@ const mysql_1 = require("../adapters/mysql"); | ||
const inflector = __importStar(require("../util/inflector")); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const Toposort = require('toposort-class'); | ||
try { | ||
// tslint:disable-next-line:no-var-requires | ||
redis = require('redis'); | ||
@@ -133,3 +131,2 @@ } | ||
const current = await this._adapter.getSchemas(); | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
@@ -141,3 +138,2 @@ const modelClass = this.models[model]; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const column in modelClass._schema) { | ||
@@ -153,3 +149,2 @@ const property = modelClass._schema[column]; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
@@ -164,3 +159,2 @@ const modelClass = this.models[model]; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const model_name in this.models) { | ||
@@ -178,3 +172,2 @@ const modelClass = this.models[model_name]; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
@@ -227,3 +220,2 @@ const modelClass = this.models[model]; | ||
const current = await this._adapter.getSchemas(); | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
@@ -235,3 +227,2 @@ const modelClass = this.models[model]; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const column in modelClass._schema) { | ||
@@ -244,3 +235,2 @@ const property = modelClass._schema[column]; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
@@ -252,3 +242,2 @@ const modelClass = this.models[model]; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
@@ -263,3 +252,2 @@ const modelClass = this.models[model]; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
@@ -510,3 +498,2 @@ const modelClass = this.models[model]; | ||
const args = (options.models || []).map((model) => { | ||
// tslint:disable-next-line:only-arrow-functions | ||
const txModel = function (data) { | ||
@@ -616,3 +603,2 @@ const instance = new model(data); | ||
_initializeModels() { | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
@@ -628,7 +614,6 @@ const modelClass = this.models[model]; | ||
_checkArchive() { | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
const modelClass = this.models[model]; | ||
if (modelClass.archive && !modelClass._connection.models.hasOwnProperty('_Archive')) { | ||
// tslint:disable-next-line:max-classes-per-file | ||
if (modelClass.archive && !Object.prototype.hasOwnProperty.call(modelClass._connection.models, '_Archive')) { | ||
// eslint-disable-next-line @typescript-eslint/class-name-casing | ||
const _Archive = class extends model_1.BaseModel { | ||
@@ -645,7 +630,5 @@ }; | ||
const t = new Toposort(); | ||
// tslint:disable-next-line:forin | ||
for (const model in this.models) { | ||
const modelClass = this.models[model]; | ||
t.add(model, []); | ||
// tslint:disable-next-line:forin | ||
for (const name in modelClass._associations) { | ||
@@ -716,6 +699,5 @@ const association = modelClass._associations[name]; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const column in this.models[model]._schema) { | ||
const property = this.models[model]._schema[column]; | ||
if (property.record_id && data.hasOwnProperty(column)) { | ||
if (property.record_id && Object.prototype.hasOwnProperty.call(data, column)) { | ||
if (property.array && Array.isArray(data[column])) { | ||
@@ -770,3 +752,3 @@ data[column] = data[column].map((value) => { | ||
// getter must be created per instance due to __scope | ||
if (!this.hasOwnProperty(columnGetter)) { | ||
if (!Object.prototype.hasOwnProperty.call(this, columnGetter)) { | ||
getter = async (reload) => { | ||
@@ -833,3 +815,3 @@ // this is getter.__scope in normal case (this_model_instance.target_model_name()), | ||
// getter must be created per instance due to __scope | ||
if (!this.hasOwnProperty(columnGetter)) { | ||
if (!Object.prototype.hasOwnProperty.call(this, columnGetter)) { | ||
getter = async (reload) => { | ||
@@ -887,3 +869,3 @@ // this is getter.__scope in normal case (this_model_instance.target_model_name()), | ||
// getter must be created per instance due to __scope | ||
if (!this.hasOwnProperty(columnGetter)) { | ||
if (!Object.prototype.hasOwnProperty.call(this, columnGetter)) { | ||
getter = async (reload) => { | ||
@@ -944,3 +926,3 @@ // this is getter.__scope in normal case (this_model_instance.target_model_name()), | ||
records.forEach((record) => { | ||
if (!record.hasOwnProperty(column)) { | ||
if (!Object.prototype.hasOwnProperty.call(record, column)) { | ||
if (options.lean) { | ||
@@ -985,3 +967,3 @@ record[column] = null; | ||
} | ||
if (!records.hasOwnProperty(column)) { | ||
if (!Object.prototype.hasOwnProperty.call(records, column)) { | ||
if (options.lean) { | ||
@@ -996,3 +978,3 @@ records[column] = null; | ||
} | ||
else if (!records.hasOwnProperty(column)) { | ||
else if (!Object.prototype.hasOwnProperty.call(records, column)) { | ||
if (options.lean) { | ||
@@ -999,0 +981,0 @@ records[column] = null; |
@@ -69,6 +69,6 @@ /// <reference types="node" /> | ||
static _schema: IModelSchemaInternal; | ||
static _object_column_classes: { | ||
static _object_column_classes: Array<{ | ||
column: string; | ||
klass: any; | ||
}[]; | ||
}>; | ||
static _integrities: any[]; | ||
@@ -201,3 +201,3 @@ static _associations: { | ||
*/ | ||
static createBulk<M extends BaseModel>(this: (new (data?: any) => M) & typeof BaseModel, data?: ModelValueObject<M>[], options?: { | ||
static createBulk<M extends BaseModel>(this: (new (data?: any) => M) & typeof BaseModel, data?: Array<ModelValueObject<M>>, options?: { | ||
transaction?: Transaction; | ||
@@ -204,0 +204,0 @@ }): Promise<M[]>; |
@@ -13,4 +13,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("util"); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const util_1 = require("util"); | ||
const connection_1 = require("../connection"); | ||
@@ -57,3 +57,2 @@ const query_1 = require("../query"); | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const column in schema) { | ||
@@ -83,5 +82,4 @@ const property = schema[column]; | ||
// if this has 4 arguments, this is called from adapter with database record data | ||
const id = arguments[1]; | ||
const selected_columns = arguments[2]; | ||
const selected_columns_raw = arguments[3]; | ||
// eslint-disable-next-line prefer-rest-params | ||
const [id, selected_columns, selected_columns_raw] = [arguments[1], arguments[2], arguments[3]]; | ||
adapter.setValuesFromDB(this, data, schema, selected_columns); | ||
@@ -104,3 +102,2 @@ ctor._collapseNestedNulls(this, selected_columns_raw, ctor.dirty_tracking ? this._intermediates : undefined); | ||
else { | ||
// tslint:disable-next-line:forin | ||
for (const column in schema) { | ||
@@ -133,7 +130,5 @@ const property = schema[column]; | ||
static newModel(connection, name, schema) { | ||
// tslint:disable-next-line:variable-name max-classes-per-file | ||
const NewModel = class extends BaseModel { | ||
}; | ||
NewModel.connection(connection, name); | ||
// tslint:disable-next-line:forin | ||
for (const column_name in schema) { | ||
@@ -151,3 +146,3 @@ const property = schema[column_name]; | ||
static connection(connection, name) { | ||
if (this.hasOwnProperty('_connection')) { | ||
if (Object.prototype.hasOwnProperty.call(this, '_connection')) { | ||
throw new Error('Model::connection was called twice'); | ||
@@ -175,3 +170,3 @@ } | ||
static _checkConnection() { | ||
if (this.hasOwnProperty('_connection')) { | ||
if (Object.prototype.hasOwnProperty.call(this, '_connection')) { | ||
return; | ||
@@ -192,3 +187,2 @@ } | ||
if (lodash_1.default.isPlainObject(type_or_property) && (!type_or_property.type || type_or_property.type.type)) { | ||
// tslint:disable-next-line:forin | ||
for (const subcolumn in type_or_property) { | ||
@@ -200,3 +194,3 @@ const subproperty = type_or_property[subcolumn]; | ||
} | ||
if (this._schema.hasOwnProperty(path)) { | ||
if (Object.prototype.hasOwnProperty.call(this._schema, path)) { | ||
// if using association, a column may be defined more than twice (by hasMany and belongsTo, for example) | ||
@@ -343,3 +337,2 @@ // overwrite some properties if given later | ||
let has_non_null = false; | ||
// tslint:disable-next-line:forin | ||
for (const key in obj[last]) { | ||
@@ -603,2 +596,3 @@ const value = obj[last][key]; | ||
let last; | ||
// eslint-disable-next-line prefer-const | ||
[obj, last] = util.getLeafOfPath(data, property._parts, false); | ||
@@ -710,3 +704,2 @@ const value = obj && obj[last]; | ||
// value>>0 checkes integer and 32bit | ||
// tslint:disable-next-line:no-bitwise | ||
if (isNaN(value) || (value >> 0) !== value) { | ||
@@ -749,3 +742,3 @@ throw new Error(`'${column}' is not an integer`); | ||
get(path) { | ||
if (this._intermediates.hasOwnProperty(path)) { | ||
if (Object.prototype.hasOwnProperty.call(this._intermediates, path)) { | ||
return this._intermediates[path]; | ||
@@ -767,9 +760,7 @@ } | ||
set(path, value) { | ||
if (this._intermediates.hasOwnProperty(path)) { | ||
if (Object.prototype.hasOwnProperty.call(this._intermediates, path)) { | ||
const obj = this._intermediates[path]; | ||
// tslint:disable-next-line:forin | ||
for (const k in obj) { | ||
obj[k] = undefined; | ||
} | ||
// tslint:disable-next-line:forin | ||
for (const k in value) { | ||
@@ -785,3 +776,3 @@ obj[k] = value[k]; | ||
} | ||
if (!this._prev_attributes.hasOwnProperty(path)) { | ||
if (!Object.prototype.hasOwnProperty.call(this._prev_attributes, path)) { | ||
this._prev_attributes[path] = prev_value; | ||
@@ -803,3 +794,2 @@ } | ||
reset() { | ||
// tslint:disable-next-line:forin | ||
for (const path in this._prev_attributes) { | ||
@@ -848,3 +838,3 @@ const value = this._prev_attributes[path]; | ||
if (options.validate !== false) { | ||
await this.validate(); | ||
this.validate(); | ||
return await this.save(Object.assign(Object.assign({}, options), { validate: false })); | ||
@@ -883,3 +873,2 @@ } | ||
const schema = ctor._schema; | ||
// tslint:disable-next-line:forin | ||
for (const column in schema) { | ||
@@ -944,3 +933,2 @@ const property = schema[column]; | ||
const schema = ctor._schema; | ||
// tslint:disable-next-line:forin | ||
for (const column in schema) { | ||
@@ -1004,3 +992,2 @@ const property = schema[column]; | ||
const schema = ctor._schema; | ||
// tslint:disable-next-line:forin | ||
for (const path in this._prev_attributes) { | ||
@@ -1029,3 +1016,2 @@ ctor._buildSaveDataColumn(data, this._attributes, path, schema[path], true); | ||
const schema = ctor._schema; | ||
// tslint:disable-next-line:forin | ||
for (const column in schema) { | ||
@@ -1032,0 +1018,0 @@ const property = schema[column]; |
@@ -28,3 +28,3 @@ /// <reference types="node" /> | ||
} | ||
export interface IQuerySingle<M extends BaseModel, T = M> extends PromiseLike<T | null> { | ||
export interface IQuerySingle<M extends BaseModel, T = M> extends PromiseLike<T> { | ||
clone(): IQuerySingle<M, T>; | ||
@@ -47,3 +47,3 @@ find(id: RecordID): IQuerySingle<M, T>; | ||
group<U>(group_by: string | null, fields?: object): IQuerySingle<M, U>; | ||
one(): IQuerySingle<M, T>; | ||
one(): IQuerySingleNull<M, T>; | ||
limit(limit?: number): IQuerySingle<M, T>; | ||
@@ -61,2 +61,41 @@ skip(skip?: number): IQuerySingle<M, T>; | ||
skip_log?: boolean; | ||
}): PromiseLike<T>; | ||
stream(): stream.Readable; | ||
explain(): PromiseLike<any>; | ||
count(): PromiseLike<number>; | ||
update(updates: object): PromiseLike<number>; | ||
upsert(updates: object): PromiseLike<void>; | ||
delete(options?: any): PromiseLike<number>; | ||
} | ||
interface IQuerySingleNull<M extends BaseModel, T = M> extends PromiseLike<T | null> { | ||
clone(): IQuerySingleNull<M, T>; | ||
find(id: RecordID): IQuerySingle<M, T>; | ||
find(id: RecordID[]): IQueryArray<M, T>; | ||
findPreserve(id: RecordID[]): IQueryArray<M, T>; | ||
near(target: object): IQuerySingleNull<M, T>; | ||
where(condition?: object): IQuerySingleNull<M, T>; | ||
select<K extends ModelColumnNamesWithId<M>>(columns: K[]): IQuerySingleNull<M, Pick<M, K>>; | ||
select<K extends ModelColumnNamesWithId<M>>(columns?: string): IQuerySingleNull<M, Pick<M, K>>; | ||
selectSingle<K extends ModelColumnNamesWithId<M>>(column: K): IQuerySingleNull<M, M[K]>; | ||
order(orders?: string): IQuerySingleNull<M, T>; | ||
group<G extends ModelColumnNamesWithId<M>, F>(group_by: G | G[], fields?: F): IQuerySingleNull<M, { | ||
[field in keyof F]: number; | ||
} & Pick<M, G>>; | ||
group<F>(group_by: null, fields?: F): IQuerySingleNull<M, { | ||
[field in keyof F]: number; | ||
}>; | ||
group<U>(group_by: string | null, fields?: object): IQuerySingleNull<M, U>; | ||
one(): IQuerySingleNull<M, T>; | ||
limit(limit?: number): IQuerySingleNull<M, T>; | ||
skip(skip?: number): IQuerySingleNull<M, T>; | ||
lean(lean?: boolean): IQuerySingleNull<M, T>; | ||
if(condition: boolean): IQuerySingleNull<M, T>; | ||
endif(): IQuerySingleNull<M, T>; | ||
cache(options: IQueryOptions['cache']): IQuerySingleNull<M, T>; | ||
include(column: string, select?: string): IQuerySingleNull<M, T>; | ||
transaction(transaction?: Transaction): IQuerySingleNull<M, T>; | ||
using(node: 'master' | 'read'): IQuerySingleNull<M, T>; | ||
index_hint(hint: string): IQuerySingleNull<M, T>; | ||
exec(options?: { | ||
skip_log?: boolean; | ||
}): PromiseLike<T | null>; | ||
@@ -88,3 +127,3 @@ stream(): stream.Readable; | ||
group<U>(group_by: string | null, fields?: object): IQueryArray<M, U>; | ||
one(): IQuerySingle<M, T>; | ||
one(): IQuerySingleNull<M, T>; | ||
limit(limit?: number): IQueryArray<M, T>; | ||
@@ -99,3 +138,3 @@ skip(skip?: number): IQueryArray<M, T>; | ||
using(node: 'master' | 'read'): IQueryArray<M, T>; | ||
index_hint(hint: string): IQuerySingle<M, T>; | ||
index_hint(hint: string): IQueryArray<M, T>; | ||
exec(options?: { | ||
@@ -102,0 +141,0 @@ skip_log?: boolean; |
@@ -6,4 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const stream_1 = __importDefault(require("stream")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const stream_1 = __importDefault(require("stream")); | ||
/** | ||
@@ -460,3 +460,3 @@ * Collects conditions to query | ||
schema_columns.forEach((sc) => { | ||
if (sc.indexOf(column) === 0) { | ||
if (sc.startsWith(column)) { | ||
select.push(sc); | ||
@@ -483,3 +483,3 @@ } | ||
let asc = true; | ||
if (order[0] === '-') { | ||
if (order.startsWith('-')) { | ||
asc = false; | ||
@@ -522,3 +522,2 @@ order = order.slice(1); | ||
const schema = model._schema; | ||
// tslint:disable-next-line:forin | ||
for (let column in object) { | ||
@@ -540,3 +539,3 @@ const property = schema[path + column]; | ||
Object.keys(schema).forEach((sc) => { | ||
if (sc.indexOf(column) === 0) { | ||
if (sc.startsWith(column)) { | ||
temp[sc.substr(column.length)] = null; | ||
@@ -601,3 +600,3 @@ } | ||
const keys = Object.keys(condition); | ||
if (keys.length === 1 && this._options.group_fields.hasOwnProperty(keys[0])) { | ||
if (keys.length === 1 && Object.prototype.hasOwnProperty.call(this._options.group_fields, keys[0])) { | ||
this._options.conditions_of_group.push(condition); | ||
@@ -604,0 +603,0 @@ } |
"use strict"; | ||
// tslint:disable:max-classes-per-file | ||
// tslint:disable:variable-name | ||
/** | ||
* CORMO types | ||
* @module types | ||
* @namespace cormo | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,3 +23,2 @@ const CormoTypesString = function (length) { | ||
exports.Number = CormoTypesNumber; | ||
// tslint:disable-next-line:variable-name | ||
const CormoTypesBoolean = function () { | ||
@@ -29,3 +31,2 @@ if (!(this instanceof CormoTypesBoolean)) { | ||
exports.Boolean = CormoTypesBoolean; | ||
// tslint:disable-next-line:variable-name | ||
const CormoTypesInteger = function () { | ||
@@ -38,3 +39,2 @@ if (!(this instanceof CormoTypesInteger)) { | ||
exports.Integer = CormoTypesInteger; | ||
// tslint:disable-next-line:variable-name | ||
const CormoTypesGeoPoint = function () { | ||
@@ -47,3 +47,2 @@ if (!(this instanceof CormoTypesGeoPoint)) { | ||
exports.GeoPoint = CormoTypesGeoPoint; | ||
// tslint:disable-next-line:variable-name | ||
const CormoTypesDate = function () { | ||
@@ -56,3 +55,2 @@ if (!(this instanceof CormoTypesDate)) { | ||
exports.Date = CormoTypesDate; | ||
// tslint:disable-next-line:variable-name | ||
const CormoTypesObject = function () { | ||
@@ -65,3 +63,2 @@ if (!(this instanceof CormoTypesObject)) { | ||
exports.Object = CormoTypesObject; | ||
// tslint:disable-next-line:variable-name | ||
const CormoTypesRecordID = function () { | ||
@@ -74,3 +71,2 @@ if (!(this instanceof CormoTypesRecordID)) { | ||
exports.RecordID = CormoTypesRecordID; | ||
// tslint:disable-next-line:variable-name | ||
const CormoTypesText = function () { | ||
@@ -77,0 +73,0 @@ if (!(this instanceof CormoTypesText)) { |
@@ -14,3 +14,2 @@ "use strict"; | ||
*/ | ||
// tslint:disable-next-line:max-line-length | ||
function getLeafOfPath(obj, path, create_object = true) { | ||
@@ -17,0 +16,0 @@ const parts = Array.isArray(path) ? path.slice(0) : path.split('.'); |
{ | ||
"name": "cormo", | ||
"description": "ORM framework for Node.js", | ||
"version": "0.14.0", | ||
"version": "0.14.1", | ||
"keywords": [ | ||
@@ -24,3 +24,3 @@ "orm", | ||
"build": "rimraf lib && tsc -p src/tsconfig.build.json", | ||
"lint": "tslint -p tsconfig.json", | ||
"lint": "../../node_modules/.bin/eslint --ext .js,.ts .", | ||
"doc": "node node_modules/.bin/crojsdoc", | ||
@@ -46,9 +46,9 @@ "test:type": "tsc --noEmit", | ||
"devDependencies": { | ||
"@types/chai": "^4.2.9", | ||
"@types/chai": "^4.2.10", | ||
"@types/inflected": "^1.1.29", | ||
"@types/lodash": "^4.14.149", | ||
"@types/mocha": "^7.0.1", | ||
"@types/mongodb": "^3.3.16", | ||
"@types/node": "^13.7.4", | ||
"@types/sinon": "^7.5.1", | ||
"@types/mocha": "^7.0.2", | ||
"@types/mongodb": "^3.5.2", | ||
"@types/node": "^13.9.0", | ||
"@types/sinon": "^7.5.2", | ||
"benchmark": "^2.1.4", | ||
@@ -60,4 +60,4 @@ "chai": "^4.2.0", | ||
"microtime": "^3.0.0", | ||
"mocha": "^7.0.1", | ||
"mongodb": "^3.5.3", | ||
"mocha": "^7.1.0", | ||
"mongodb": "^3.5.5", | ||
"mysql": "^2.18.1", | ||
@@ -68,9 +68,8 @@ "pg": "^7.18.2", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^9.0.0", | ||
"sinon": "^9.0.1", | ||
"sqlite3": "^4.1.1", | ||
"ts-node": "^8.6.2", | ||
"tslint": "^6.0.0", | ||
"typescript": "^3.8.2" | ||
"typescript": "^3.8.3" | ||
}, | ||
"gitHead": "14bd5a6495ea004434d41172ef4228e9d1003ee1" | ||
"gitHead": "69fb9968c40508d9864694352ae8620b26eb296c" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24
53
317867
8664