Skip to content

Commit

Permalink
feat: throw if property name is required but not provided
Browse files Browse the repository at this point in the history
BREAKING CHANGE: an error will now be thrown immediately from methods that require a property name if none is provided.
  • Loading branch information
haltcase committed Jun 12, 2019
1 parent cc46062 commit ede6363
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ export class Trilogy {
defaultValue?: any
): Promise<any> {
const [table, column] = location.split('.', 2)

invariant(column, 'property name is required, ex: `get("users.rank")`')

const model = this.getModel(table)
return model.get(column, criteria, defaultValue)
}
Expand All @@ -402,6 +405,9 @@ export class Trilogy {
*/
set <T> (location: string, criteria: types.Criteria, value: T) {
const [table, column] = location.split('.', 2)

invariant(column, 'property name is required, ex: `set("users.rank")`')

const model = this.getModel(table)
return model.set(column, criteria, value)
}
Expand All @@ -421,6 +427,9 @@ export class Trilogy {
defaultValue?: any
): Promise<any> {
const [table, column] = location.split('.', 2)

invariant(column, 'property name is required, ex: `getRaw("users.rank")`')

const model = this.getModel(table)
return model.getRaw(column, criteria, defaultValue)
}
Expand All @@ -434,6 +443,9 @@ export class Trilogy {
*/
setRaw <T> (location: string, criteria: types.Criteria, value: T) {
const [table, column] = location.split('.', 2)

invariant(column, 'property name is required, ex: `setRaw("users.rank")`')

const model = this.getModel(table)
return model.setRaw(column, criteria, value)
}
Expand Down Expand Up @@ -536,6 +548,9 @@ export class Trilogy {
*/
min (location: string, criteria: types.Criteria, options?: types.AggregateOptions) {
const [table, column] = location.split('.', 2)

invariant(column, 'property name is required, ex: `min("users.rank")`')

const model = this.getModel(table)
return model.min(column, criteria, options)
}
Expand All @@ -550,6 +565,9 @@ export class Trilogy {
*/
max (location: string, criteria: types.Criteria, options?: types.AggregateOptions) {
const [table, column] = location.split('.', 2)

invariant(column, 'property name is required, ex: `max("users.rank")`')

const model = this.getModel(table)
return model.max(column, criteria, options)
}
Expand Down

0 comments on commit ede6363

Please sign in to comment.