Adds Event system and automatic messages
This commit is contained in:
parent
0e10ea3cab
commit
2f826fbf36
20 changed files with 428 additions and 18 deletions
|
|
@ -3,8 +3,12 @@ import {Model} from "../Models/Model";
|
|||
import { Nullable } from "../types/Nullable";
|
||||
import {DatabaseDefinition} from "../Database/DatabaseDefinition";
|
||||
import {debug} from "node:util";
|
||||
import {Container} from "../Container/Container";
|
||||
import {EventHandler} from "../Events/EventHandler";
|
||||
import {ElementCreatedEvent} from "../Events/ElementCreatedEvent";
|
||||
|
||||
export class Repository<ModelType extends Model, IntermediateModelType = unknown> {
|
||||
|
||||
constructor(
|
||||
protected readonly database: DatabaseConnection,
|
||||
public readonly schema: DatabaseDefinition,
|
||||
|
|
@ -30,7 +34,11 @@ export class Repository<ModelType extends Model, IntermediateModelType = unknown
|
|||
const sql = `INSERT INTO ${this.schema.name}(${Object.keys(createObject).join(',')})
|
||||
VALUES (${Object.keys(createObject).map(() => "?").join(',')})`;
|
||||
const result = this.database.execute(sql, ...Object.values(createObject));
|
||||
return result.lastInsertRowid;
|
||||
const id = result.lastInsertRowid;
|
||||
|
||||
Container.get<EventHandler>(EventHandler.name).dispatch(new ElementCreatedEvent<ModelType>(this.schema.name, instance, id));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public update(instance: Partial<ModelType>&{id: number}): boolean {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue