Implement scopes on models and support interacting with them via ModelBuilder
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -69,6 +69,13 @@ export abstract class AbstractBuilder<T> extends AppClass {
|
||||
*/
|
||||
public abstract getResultIterable(): AbstractResultIterable<T>
|
||||
|
||||
/**
|
||||
* Get a copy of this builder with its values finalized.
|
||||
*/
|
||||
public finalize(): AbstractBuilder<T> {
|
||||
return this.clone()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the current query to a new AbstractBuilder instance with the same properties.
|
||||
*/
|
||||
@@ -489,7 +496,7 @@ export abstract class AbstractBuilder<T> extends AppClass {
|
||||
throw new ErrorWithContext(`No connection specified to execute update query.`)
|
||||
}
|
||||
|
||||
const query = this.registeredConnection.dialect().renderUpdate(this, data)
|
||||
const query = this.registeredConnection.dialect().renderUpdate(this.finalize(), data)
|
||||
return this.registeredConnection.query(query)
|
||||
}
|
||||
|
||||
@@ -515,7 +522,7 @@ export abstract class AbstractBuilder<T> extends AppClass {
|
||||
throw new ErrorWithContext(`No connection specified to execute update query.`)
|
||||
}
|
||||
|
||||
const query = this.registeredConnection.dialect().renderDelete(this)
|
||||
const query = this.registeredConnection.dialect().renderDelete(this.finalize())
|
||||
return this.registeredConnection.query(query)
|
||||
}
|
||||
|
||||
@@ -548,7 +555,7 @@ export abstract class AbstractBuilder<T> extends AppClass {
|
||||
throw new ErrorWithContext(`No connection specified to execute update query.`)
|
||||
}
|
||||
|
||||
const query = this.registeredConnection.dialect().renderInsert(this, rowOrRows)
|
||||
const query = this.registeredConnection.dialect().renderInsert(this.finalize(), rowOrRows)
|
||||
return this.registeredConnection.query(query)
|
||||
}
|
||||
|
||||
@@ -560,7 +567,7 @@ export abstract class AbstractBuilder<T> extends AppClass {
|
||||
throw new ErrorWithContext(`No connection specified to execute update query.`)
|
||||
}
|
||||
|
||||
const query = this.registeredConnection.dialect().renderExistential(this)
|
||||
const query = this.registeredConnection.dialect().renderExistential(this.finalize())
|
||||
const result = await this.registeredConnection.query(query)
|
||||
return Boolean(result.rows.first())
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@ export class Builder extends AbstractBuilder<QueryRow> {
|
||||
throw new ErrorWithContext(`No connection specified to fetch iterator for query.`)
|
||||
}
|
||||
|
||||
return Container.getContainer().make<ResultIterable>(ResultIterable, this, this.registeredConnection)
|
||||
return Container.getContainer().make<ResultIterable>(ResultIterable, this.finalize(), this.registeredConnection)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user