responses
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
jusax23 2023-02-22 11:13:43 +01:00
parent cba4248727
commit f63c0cf6d0
4 changed files with 40 additions and 6 deletions

View file

@ -4,6 +4,7 @@ import { Handler } from './defaultHandler';
import { Query } from './query';
import { attributeSettings, extendedAttributeSettings, onAction, dbType } from './types';
import { TableAlias } from "./alias"
import { insertResponse, readResponse, writeResponse } from "./responses"
//import { postgresHandler } from "./postgresHandler"
@ -163,3 +164,4 @@ export class Table {
export * from './funcs';
export { onAction };
export { dbType as databaseType }
export { readResponse, writeResponse, insertResponse }

View file

@ -1,5 +1,5 @@
import { AttributeAlias, TableAlias } from "./alias";
import { Attribute, DB, Table } from "./db"
import { Attribute, DB, insertResponse, readResponse, Table, writeResponse } from "./db"
import { Aggregation, checkConstraint, joinCross, Datatype, foreignConstraint, Modifier, joinNatural, onJoin, uniqueConstraint, usingJoin } from "./dbStructure"
import { insertQuery, Query, QueryBuilder, removeQuery, selectQuery, updateQuery } from "./query"
import { allModifierInput, joinType, onAction, primaryData } from "./types"
@ -570,6 +570,12 @@ export class Handler {
},
}
responses = {
readResponse: (resp: any) => new readResponse(resp),
writeResponse: (resp: any) => new writeResponse(resp.affectedRows),
insertResponse: (resp: any) => new insertResponse(resp.affectedRows, resp.insertId),
}
aggregations = {
count: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "count(" + a.toString(handler) + ")" }]),
sum: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "sum(" + a.toString(handler) + ")" }]),

View file

@ -100,7 +100,8 @@ export class selectQuery {
const handler = db.getHandler();
const builder = this.serialize(handler);
const s = handler.builders.query(builder);
return await db.query(s);
let readResp = await db.query(s);
return db.getHandler().responses.readResponse(readResp);
}
}
@ -137,7 +138,8 @@ export class insertQuery {
const handler = db.getHandler();
const builder = this.serialize(handler);
const s = handler.builders.query(builder);
return await db.query(s);
let readResp = await db.query(s);
return db.getHandler().responses.insertResponse(readResp);
}
}
@ -165,7 +167,8 @@ export class updateQuery {
const handler = db.getHandler();
const builder = this.serialize(handler);
const s = handler.builders.query(builder);
return await db.query(s);
let readResp = await db.query(s);
return db.getHandler().responses.writeResponse(readResp);
}
}
@ -186,6 +189,7 @@ export class removeQuery {
const handler = db.getHandler();
const builder = this.serialize(handler);
const s = handler.builders.query(builder);
return await db.query(s);
let readResp = await db.query(s);
return db.getHandler().responses.writeResponse(readResp);
}
}

22
src/responses.ts Normal file
View file

@ -0,0 +1,22 @@
export class readResponse extends Array{
constructor(rows:({[key: string]:any})[]){
super();
this.push(...rows);
}
}
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;
}
}