Created
October 1, 2017 11:07
-
-
Save bas080/e08145e90ce474e80956f870018ecba2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const knex = require('knex'); | |
module.exports = { | |
knexline, | |
} | |
function knexline(model, qb) { | |
const modelTable = model.identity; | |
qb = qb || knex(modelTable); | |
const methods = { | |
criteria, | |
join, | |
populate, | |
queryBuilder: () => qb, | |
}; | |
return methods; | |
function populate() { | |
// once it's necessary | |
} | |
function criteria(criteria) { | |
/* already built */ | |
qb = qb | |
return methods; | |
} | |
function join(property) { | |
const [table, field] = property.split('.'); | |
qb = qb.join( | |
table, | |
`${modelTable}.id`, | |
`${table}.id` | |
); | |
return methods; | |
} | |
} | |
const columns = [{ | |
property: 'location.name', | |
alias: 'Location', | |
}]; | |
//playground | |
const model = { | |
identity: 'machine', | |
}; | |
const criteria = {} | |
const joins = ['location.name']; | |
const selects = ['name', 'id']; | |
const query = joins.reduce( | |
(kl, join) => kl.join(join), | |
knexline(model).criteria(criteria) | |
) | |
.queryBuilder() | |
.select(selects) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment