Compare commits
2 commits
d647fba5a9
...
57544dffd2
Author | SHA1 | Date | |
---|---|---|---|
57544dffd2 | |||
c9f76a0799 |
5 changed files with 22 additions and 8 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "dblang",
|
"name": "dblang",
|
||||||
"version": "0.9.0",
|
"version": "0.9.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "dblang",
|
"name": "dblang",
|
||||||
"version": "0.9.0",
|
"version": "0.9.2",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mariadb": "^3.0.2",
|
"mariadb": "^3.0.2",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "dblang",
|
"name": "dblang",
|
||||||
"version": "0.9.0",
|
"version": "0.9.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/db.js",
|
"main": "dist/db.js",
|
||||||
"types": "dist/db.d.ts",
|
"types": "dist/db.d.ts",
|
||||||
|
|
|
@ -132,10 +132,12 @@ export class uniqueConstraint implements Constraint {
|
||||||
this.attrs = attrs;
|
this.attrs = attrs;
|
||||||
}
|
}
|
||||||
check(table: Table): boolean | string {
|
check(table: Table): boolean | string {
|
||||||
|
let prim = true;
|
||||||
for (let i = 0; i < this.attrs.length; i++) {
|
for (let i = 0; i < this.attrs.length; i++) {
|
||||||
if (this.attrs[i].ops.primaryKey) return "Can not combine unique Constraint and primary key";
|
if (!this.attrs[i].ops.primaryKey) prim = false;
|
||||||
if (this.attrs[i].table != table) return "Referencing Attributes must be in host Table.";
|
if (this.attrs[i].table != table) return "Referencing Attributes must be in host Table.";
|
||||||
}
|
}
|
||||||
|
if (prim) return "Can not combine unique Constraint and primary key";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uses(attr: Attribute): boolean {
|
uses(attr: Attribute): boolean {
|
||||||
|
|
|
@ -604,6 +604,13 @@ export class Handler {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catcherrors = {
|
||||||
|
insert: (err: any) => {
|
||||||
|
if(err?.code == "ER_DUP_ENTRY") return {affectedRows: 0, insertId: -1};
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
responses = {
|
responses = {
|
||||||
readResponse: (resp: any) => new readResponse(resp),
|
readResponse: (resp: any) => new readResponse(resp),
|
||||||
writeResponse: (resp: any) => new writeResponse(resp.affectedRows),
|
writeResponse: (resp: any) => new writeResponse(resp.affectedRows),
|
||||||
|
|
13
src/query.ts
13
src/query.ts
|
@ -138,8 +138,13 @@ export class insertQuery {
|
||||||
const handler = db.getHandler();
|
const handler = db.getHandler();
|
||||||
const builder = this.serialize(handler);
|
const builder = this.serialize(handler);
|
||||||
const s = handler.builders.query(builder);
|
const s = handler.builders.query(builder);
|
||||||
let readResp = await db.query(s, printQuery);
|
let readResp: any;
|
||||||
return db.getHandler().responses.insertResponse(readResp);
|
try {
|
||||||
|
readResp = await db.query(s, printQuery);
|
||||||
|
} catch (err) {
|
||||||
|
readResp = handler.catcherrors.insert(err);
|
||||||
|
}
|
||||||
|
return handler.responses.insertResponse(readResp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +173,7 @@ export class updateQuery {
|
||||||
const builder = this.serialize(handler);
|
const builder = this.serialize(handler);
|
||||||
const s = handler.builders.query(builder);
|
const s = handler.builders.query(builder);
|
||||||
let readResp = await db.query(s, printQuery);
|
let readResp = await db.query(s, printQuery);
|
||||||
return db.getHandler().responses.writeResponse(readResp);
|
return handler.responses.writeResponse(readResp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +195,6 @@ export class removeQuery {
|
||||||
const builder = this.serialize(handler);
|
const builder = this.serialize(handler);
|
||||||
const s = handler.builders.query(builder);
|
const s = handler.builders.query(builder);
|
||||||
let readResp = await db.query(s, printQuery);
|
let readResp = await db.query(s, printQuery);
|
||||||
return db.getHandler().responses.writeResponse(readResp);
|
return handler.responses.writeResponse(readResp);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue