ormius
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,2 +0,2 @@ | ||
const { TYPES } = require('./types') | ||
const { TYPES, RELATION_TYPES } = require('./types') | ||
@@ -27,12 +27,18 @@ class Query { | ||
let currentCondition | ||
if (this.model[column].type === TYPES.BELONGS_TO) { | ||
const parent = new this.model[column].parent.class(this.connection) | ||
selectQuery = `SELECT ??, ${this.allowedColumns(parent.model, parent.modelName).join(',')} FROM ?? LEFT JOIN ?? ON ??=?? WHERE ??=?` | ||
currentCondition = [this.selectColumns, this.modelName, parent.modelName, | ||
`${parent.modelName}.${this.model[column].parent.attribute}`, | ||
`${this.modelName}.${this.model[column].from}`, | ||
`${parent.modelName}.${this.model[column].parent.attribute}`, condition] | ||
} else { | ||
selectQuery = 'SELECT ?? FROM ?? WHERE ??=?' | ||
currentCondition = [this.selectColumns, this.modelName, column, condition] | ||
switch (this.model[column].type) { | ||
case TYPES.STRING: | ||
case TYPES.INT: | ||
selectQuery = 'SELECT ?? FROM ?? WHERE ??=?' | ||
currentCondition = [this.selectColumns, this.modelName, column, condition] | ||
break | ||
case TYPES.BELONGS_TO: | ||
const { model, modelName } = this.model[column].parent.class | ||
selectQuery = `SELECT ??, ${this.allowedColumns(model, modelName).join(',')} FROM ?? LEFT JOIN ?? ON ??=?? WHERE ??=?` | ||
currentCondition = [this.selectColumns, this.modelName, modelName, | ||
`${modelName}.${this.model[column].parent.attribute}`, | ||
`${this.modelName}.${this.model[column].from}`, | ||
`${modelName}.${this.model[column].parent.attribute}`, condition] | ||
break | ||
default: | ||
throw new Error(`Not supported type ${this.model[column].type}`) | ||
} | ||
@@ -84,3 +90,3 @@ if (this.currentQuery !== '') { | ||
// otherModel ? `${modelName}.${field} as ${modelName}_${field}` : | ||
return model[field].type !== TYPES.BELONGS_TO | ||
return !RELATION_TYPES.includes(model[field].type) | ||
}).map(field => { | ||
@@ -87,0 +93,0 @@ if (otherModel) { |
const TYPES = { | ||
INT: 'int', | ||
STRING: 'string', | ||
BELONGS_TO: 'belongs_to' | ||
BELONGS_TO: 'belongs_to', | ||
HAS_MANY: 'has_many' | ||
} | ||
const RELATION_TYPES = [TYPES.BELONGS_TO, TYPES.HAS_MANY] | ||
module.exports = { | ||
TYPES | ||
TYPES, | ||
RELATION_TYPES | ||
} |
{ | ||
"name": "ormius", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "index.js", | ||
"author": "Adele Bendayan", | ||
"license": "MIT", | ||
"scripts": { | ||
"example": "nodemon examples/example.js" | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"index.js", | ||
@@ -9,0 +13,0 @@ "lib/" |
@@ -9,1 +9,14 @@ # Ormius | ||
At this point, ormius support only mysql. | ||
### Feature plan | ||
List of features planned to get to version 1 | ||
- [X] Belongs to | ||
- [X] Has many | ||
- [ ] Has one | ||
- [ ] Support all data types | ||
- [ ] Migrate data structure | ||
- [ ] Migrate data | ||
- [ ] Jest | ||
- [ ] Security tests | ||
- [ ] Support postgres |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
8999
7
223
1
22