Implement scopes on models and support interacting with them via ModelBuilder
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-11-11 16:42:37 -06:00
parent d92c8b5409
commit 0a9dd30909
9 changed files with 229 additions and 13 deletions

View File

@@ -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())
}

View File

@@ -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)
}
}