Added Joins #2
2 changed files with 26 additions and 5 deletions
29
readme.md
29
readme.md
|
@ -11,7 +11,7 @@ Features:
|
||||||
- [x] remove Query
|
- [x] remove Query
|
||||||
- [x] create Schema
|
- [x] create Schema
|
||||||
- [x] remove unused Schema
|
- [x] remove unused Schema
|
||||||
- [ ] joins
|
- [x] joins
|
||||||
- [ ] change Schema
|
- [ ] change Schema
|
||||||
- [ ] Key-Value Store Shortcut
|
- [ ] Key-Value Store Shortcut
|
||||||
- [ ] Views
|
- [ ] Views
|
||||||
|
@ -93,7 +93,7 @@ See: [Modifiers](#modifier), [Aggregations](#aggregations)
|
||||||
|
|
||||||
#### Select:
|
#### Select:
|
||||||
```javascript
|
```javascript
|
||||||
import {select} from "dblang"
|
import { select } from "dblang"
|
||||||
|
|
||||||
let res = await select([Table2.AttrName2], Table1)
|
let res = await select([Table2.AttrName2], Table1)
|
||||||
.where(eq(Table2.AttrName2, 5)) //optional
|
.where(eq(Table2.AttrName2, 5)) //optional
|
||||||
|
@ -101,12 +101,31 @@ let res = await select([Table2.AttrName2], Table1)
|
||||||
.having(le(Table2.AttrName3, 5)) //optional
|
.having(le(Table2.AttrName3, 5)) //optional
|
||||||
.limit(10) //optional
|
.limit(10) //optional
|
||||||
.query(db);
|
.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:
|
#### Insert:
|
||||||
```javascript
|
```javascript
|
||||||
import {select} from "dblang"
|
import { select } from "dblang"
|
||||||
|
|
||||||
await insert(Table2.AttrName2, Table2.AttrName3)
|
await insert(Table2.AttrName2, Table2.AttrName3)
|
||||||
.add(1, 2)
|
.add(1, 2)
|
||||||
|
@ -121,6 +140,8 @@ await insert(Table2.AttrName2, Table2.AttrName3)
|
||||||
|
|
||||||
#### Update:
|
#### Update:
|
||||||
```javascript
|
```javascript
|
||||||
|
import { update } from "dblang"
|
||||||
|
|
||||||
await update(Table2)
|
await update(Table2)
|
||||||
.set(Table2.AttrName2, plus(Table2.AttrName2,1))
|
.set(Table2.AttrName2, plus(Table2.AttrName2,1))
|
||||||
.set(Table2.AttrName3, minus(Table2.AttrName2,1))
|
.set(Table2.AttrName3, minus(Table2.AttrName2,1))
|
||||||
|
@ -130,6 +151,8 @@ await update(Table2)
|
||||||
|
|
||||||
#### Remove:
|
#### Remove:
|
||||||
```javascript
|
```javascript
|
||||||
|
import { remove } from "dblang"
|
||||||
|
|
||||||
await remove(Table2)
|
await remove(Table2)
|
||||||
.where(geq(Table2.AttrName2, 5))
|
.where(geq(Table2.AttrName2, 5))
|
||||||
.query(db);
|
.query(db);
|
||||||
|
|
|
@ -5,8 +5,6 @@ import { allModifierInput, joinType, onAction, primaryData } from "./types"
|
||||||
|
|
||||||
export class Handler {
|
export class Handler {
|
||||||
async syncDB(db: DB, handler: Handler, deleteInDB: boolean = false) {
|
async syncDB(db: DB, handler: Handler, deleteInDB: boolean = false) {
|
||||||
console.log("start sync");
|
|
||||||
|
|
||||||
let gd = new QueryBuilder();
|
let gd = new QueryBuilder();
|
||||||
gd.addCode(`SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA = `);
|
gd.addCode(`SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA = `);
|
||||||
gd.addInjection(db.name);
|
gd.addInjection(db.name);
|
||||||
|
|
Loading…
Reference in a new issue