Comparing version 0.1.3 to 0.1.4
@@ -21,2 +21,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'Number'; | ||
} | ||
//noinspection JSUnusedGlobalSymbols | ||
@@ -23,0 +28,0 @@ /** |
@@ -21,2 +21,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'Buffer'; | ||
} | ||
//noinspection JSUnusedGlobalSymbols | ||
@@ -23,0 +28,0 @@ /** |
@@ -21,2 +21,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'Buffer'; | ||
} | ||
//noinspection JSUnusedGlobalSymbols | ||
@@ -23,0 +28,0 @@ /** |
@@ -21,2 +21,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'String'; | ||
} | ||
//noinspection JSUnusedGlobalSymbols | ||
@@ -23,0 +28,0 @@ /** |
@@ -21,2 +21,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'String'; | ||
} | ||
//noinspection JSUnusedGlobalSymbols | ||
@@ -23,0 +28,0 @@ /** |
@@ -21,2 +21,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'Date'; | ||
} | ||
/** | ||
@@ -23,0 +28,0 @@ * @param {*} value |
@@ -21,2 +21,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'Number'; | ||
} | ||
//noinspection JSCheckFunctionSignatures | ||
@@ -23,0 +28,0 @@ /** |
@@ -24,2 +24,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'Number'; | ||
} | ||
/** | ||
@@ -26,0 +31,0 @@ * @type {boolean} |
@@ -32,2 +32,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'Number'; | ||
} | ||
/** | ||
@@ -34,0 +39,0 @@ * @type {int} |
@@ -21,2 +21,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'Date'; | ||
} | ||
/** | ||
@@ -23,0 +28,0 @@ * @param {*} value |
@@ -25,2 +25,7 @@ /* UNIQORM | ||
// noinspection JSMethodCanBeStatic | ||
get jsType() { | ||
return 'String'; | ||
} | ||
/** | ||
@@ -27,0 +32,0 @@ * @param {*} value |
@@ -13,3 +13,2 @@ /* UNIQORM | ||
const assert = require('assert'); | ||
const sqb = require('sqb'); | ||
@@ -22,12 +21,21 @@ /** | ||
constructor(model, ...columns) { | ||
constructor(model, values) { | ||
this.model = model; | ||
this._columns = columns; | ||
this._values = values; | ||
} | ||
values(values) { | ||
this._values = values; | ||
returning(columns) { | ||
this._returning = | ||
columns ? Array.prototype.slice.call(arguments) : undefined; | ||
return this; | ||
} | ||
execute(...args) { | ||
return this._prepare().execute(...args); | ||
} | ||
then(...args) { | ||
return this._prepare().then(...args); | ||
} | ||
/** | ||
@@ -48,26 +56,30 @@ * @private | ||
// Test fields | ||
const columns = {}; | ||
const params = {}; | ||
Object.getOwnPropertyNames(self._values).forEach(key => { | ||
const f = model.meta.fields[key]; | ||
if (f && | ||
(!self._columns.length || | ||
self._columns.findIndex( | ||
item => item.toUpperCase() === key.toUpperCase() | ||
) >= 0 | ||
)) { | ||
columns[f.fieldName] = new RegExp(key); | ||
const v = self._values[key]; | ||
if (!(v === null || v === undefined)) { | ||
model.meta.getField(key); | ||
columns[key] = new RegExp(key); | ||
params[key] = self._values[key]; | ||
} | ||
}); | ||
return database | ||
const query = database | ||
.insert(columns) | ||
.into((schema ? schema + '.' : '') + model.tableName) | ||
.params(self._values); | ||
.params(params); | ||
if (self._returning) { | ||
const ret = {}; | ||
self._returning.forEach(c => { | ||
const f = model.meta.getField(c); | ||
ret[c] = String(f.jsType).toLowerCase(); | ||
}); | ||
query.returning(ret); | ||
} | ||
return query; | ||
} | ||
then(...args) { | ||
return this._prepare().then(...args); | ||
} | ||
} | ||
module.exports = InsertQuery; |
@@ -56,4 +56,4 @@ /* UNIQORM | ||
insert(...columns) { | ||
return new InsertQuery(this, ...columns); | ||
insert(values) { | ||
return new InsertQuery(this, values); | ||
} | ||
@@ -60,0 +60,0 @@ |
{ | ||
"name": "uniqorm", | ||
"description": "Easy to use, multi-dialect ORM framework for JavaScript", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"author": "Panates Ltd.", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
55039
1926