dblang/src/responses.ts

38 lines
946 B
TypeScript
Raw Normal View History

2023-02-27 16:33:27 +01:00
import { AttributeAlias } from "./alias.js";
import { Attribute } from "./db.js";
import { primaryData } from "./types.js";
2023-02-22 11:13:43 +01:00
2023-02-25 14:52:46 +01:00
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 })[]) {
2023-02-22 11:13:43 +01:00
super();
2023-02-27 17:59:16 +01:00
for(let i = 0; i < rows.length; i++){
this[i] = new singleResponse(rows[i])
}
2023-02-22 11:13:43 +01:00
}
}
2023-02-25 14:52:46 +01:00
export class writeResponse {
2023-02-22 11:13:43 +01:00
affectedRows: number;
2023-02-25 14:52:46 +01:00
constructor(affectedRows: number) {
2023-02-22 11:13:43 +01:00
this.affectedRows = affectedRows;
}
}
2023-02-25 14:52:46 +01:00
export class insertResponse extends writeResponse {
2023-02-22 11:13:43 +01:00
insertId: number;
2023-02-25 14:52:46 +01:00
constructor(affectedRows: number, insertId: number) {
2023-02-22 11:13:43 +01:00
super(affectedRows);
this.insertId = insertId;
}
}