-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueryBuilder.examples.js
More file actions
36 lines (27 loc) · 1.04 KB
/
queryBuilder.examples.js
File metadata and controls
36 lines (27 loc) · 1.04 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
const QueryBuilder = require('./queryBuilder').QueryBuilder;
const builder = new QueryBuilder();
const query = builder.select('table_alias.column_name', 'col_alias')
.from('table_name', 'table_alias')
.whereEquals('col_alias.column_name', 'value')
.sql();
console.log(query.sql);
console.log(query.params);
const builder2 = new QueryBuilder();
const query2 = builder2
.select(`tp.teacher_name`)
.select(`tp.id`, 'teacher_profile_id')
.from('course', 'c')
.join('teacher_course', 'tc.course_id = c.id', 'tc')
.join('teacher_profile', 'tp.user_id = tc.teacher_id', 'tp')
.join('users', 'u.id = tp.user_id', 'u')
.whereIsTrue('u.is_teacher')
.whereEquals('c.status', 'my-status')
.whereIsNotNull('tp.teacher_name')
.groupBy('tp.teacher_name')
.groupBy('tp.id')
.orderBy('tp.teacher_name', 'ASC')
.pagination({ page: 1, per: 10}, 10)
.filter({ 'tp.teacher_name': ["John Doe"] })
.sql();
console.log(query2.sql);
console.log(query2.params);