From 6901eb91b989646ef2e2164e981560e7038701a6 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Wed, 15 Feb 2023 14:46:58 +0100 Subject: [PATCH] readme.md updated --- readme.md | 29 ++++++++++++++++++++++++++--- src/defaultHandler.ts | 2 -- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index cf40cf9..7357701 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ Features: - [x] remove Query - [x] create Schema - [x] remove unused Schema -- [ ] joins +- [x] joins - [ ] change Schema - [ ] Key-Value Store Shortcut - [ ] Views @@ -93,7 +93,7 @@ See: [Modifiers](#modifier), [Aggregations](#aggregations) #### Select: ```javascript -import {select} from "dblang" +import { select } from "dblang" let res = await select([Table2.AttrName2], Table1) .where(eq(Table2.AttrName2, 5)) //optional @@ -101,12 +101,31 @@ let res = await select([Table2.AttrName2], Table1) .having(le(Table2.AttrName3, 5)) //optional .limit(10) //optional .query(db); +``` +Joins: +```javascript +import { INT, onAction } from "dblang" + +const TableA = db.newTable("TableA"); +const TableB = db.newTable("TableB"); +TableA.addAttribute("A1", INT, { + primaryKey: true +}); +TableB.addAttribute("B1", INT, { + primaryKey: true, + foreignKey:{ + link: TableA.A1, + onDelete: onAction.cascade + } +}); +let res = await select([TableA.A1, TableB.B1], innerJoinOn(eq(TableA.A1, Tableb.B1))) + .query(db); ``` #### Insert: ```javascript -import {select} from "dblang" +import { select } from "dblang" await insert(Table2.AttrName2, Table2.AttrName3) .add(1, 2) @@ -121,6 +140,8 @@ await insert(Table2.AttrName2, Table2.AttrName3) #### Update: ```javascript +import { update } from "dblang" + await update(Table2) .set(Table2.AttrName2, plus(Table2.AttrName2,1)) .set(Table2.AttrName3, minus(Table2.AttrName2,1)) @@ -130,6 +151,8 @@ await update(Table2) #### Remove: ```javascript +import { remove } from "dblang" + await remove(Table2) .where(geq(Table2.AttrName2, 5)) .query(db); diff --git a/src/defaultHandler.ts b/src/defaultHandler.ts index d30ff0f..25bc8b1 100644 --- a/src/defaultHandler.ts +++ b/src/defaultHandler.ts @@ -5,8 +5,6 @@ import { allModifierInput, joinType, onAction, primaryData } from "./types" export class Handler { async syncDB(db: DB, handler: Handler, deleteInDB: boolean = false) { - console.log("start sync"); - let gd = new QueryBuilder(); gd.addCode(`SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA = `); gd.addInjection(db.name);