dblang/src/responses.ts
jusax23 0dde68f0ad
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
complete response and fixes
2023-02-25 14:52:46 +01:00

35 lines
891 B
TypeScript

import { AttributeAlias } from "./alias";
import { Attribute } from "./db";
import { primaryData } from "./types";
export class singleResponse {
[key: string]: primaryData | any;
constructor(r: object) {
Object.assign(this, r);
}
getVal(a: Attribute | AttributeAlias) {
return this[a.toString()];
}
}
export class readResponse extends Array<singleResponse>{
constructor(rows: ({ [key: string]: primaryData })[]) {
super();
this.push(...rows.map(r => new singleResponse(r)));
}
}
export class writeResponse {
affectedRows: number;
constructor(affectedRows: number) {
this.affectedRows = affectedRows;
}
}
export class insertResponse extends writeResponse {
insertId: number;
constructor(affectedRows: number, insertId: number) {
super(affectedRows);
this.insertId = insertId;
}
}