-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhere_Sample.js
More file actions
77 lines (61 loc) · 1.69 KB
/
where_Sample.js
File metadata and controls
77 lines (61 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//NorthWind database
//Initializing the Library
var knex = require('knex')({
client: 'pg',
connection: {
host: 'localhost',
user: 'postgres',
password: 'P@ssw0rd',
database: 'NorthWind',
ssl: false
},
debug: true
});
// select by filter on customerid and contactname
knex('customers').where({
customerid: 'ALFKI',
contactname: 'Maria Anders'
}).select('companyname')
.then(result=>{
debugger;
});
//select "supplierid","unitprice","categoryid"
//from "products"
//where ("supplierid" = 6 or "unitprice" > 6) or ("categoryid" = 6)
knex('products').where(function(){
this.where('supplierid',6).orWhere('unitprice','>',6)
}).orWhere('categoryid',6)
.select('supplierid','unitprice','categoryid')
.then(result=>{
debugger;
});
//select "productid","unitprice","quantity"
// from "order_details"
//where "unitprice" > 50 and quantity between 10 and 40
knex('order_details').where('unitprice','>',50)
.andWhere(function(){
this.whereBetween('quantity',[10,40])
})
.select('productid','unitprice','quantity')
.then(result=>{
debugger;
});
//select "employeeid","city","region" from "employees" where not "city" = 'Redmond' and "region" is null
knex('employees').whereNot('city','Redmond')
.andWhere(function(){
this.whereNull('region')
})
.select('employeeid','city','region')
.then(result=>{
debugger;
});
//whereExists
//select * from "orders" where exists (select * from "order_details" where order.orderid = order_details.orderid)
knex('orders').whereExists(function(){
this.select('*').from('order_details')
.whereRaw("orders.orderid = order_details.orderid")
})
.select('*')
.then(result=>{
debugger;
})