forked from brianc/node-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema-tests.js
More file actions
53 lines (45 loc) · 2.51 KB
/
Copy pathschema-tests.js
File metadata and controls
53 lines (45 loc) · 2.51 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
'use strict';
var Harness = require('./support');
var Table = require(__dirname + '/../../lib/table');
var userWithSchema = Table.define({
schema: 'staging',
name: 'user',
quote: true,
columns: ['id','name']
});
Harness.test({
query : userWithSchema.select(userWithSchema.id).from(userWithSchema),
pg : 'SELECT "staging"."user"."id" FROM "staging"."user"',
sqlite: 'SELECT "staging"."user"."id" FROM "staging"."user"',
mysql : 'SELECT `staging`.`user`.`id` FROM `staging`.`user`'
});
Harness.test({
query : userWithSchema.select(userWithSchema.id, userWithSchema.name).from(userWithSchema),
pg : 'SELECT "staging"."user"."id", "staging"."user"."name" FROM "staging"."user"',
sqlite: 'SELECT "staging"."user"."id", "staging"."user"."name" FROM "staging"."user"',
mysql : 'SELECT `staging`.`user`.`id`, `staging`.`user`.`name` FROM `staging`.`user`'
});
var uws = userWithSchema.as('uws');
Harness.test({
query : uws.select(uws.name).from(uws),
pg :'SELECT "uws"."name" FROM "staging"."user" AS "uws"',
sqlite:'SELECT "uws"."name" FROM "staging"."user" AS "uws"',
mysql :'SELECT `uws`.`name` FROM `staging`.`user` AS `uws`'
});
var postWithSchema = Table.define({
schema: 'dev',
name: 'post',
columns: ['id', 'userId', 'content']
});
Harness.test({
query : userWithSchema.select(userWithSchema.name, postWithSchema.content).from(userWithSchema.join(postWithSchema).on(userWithSchema.id.equals(postWithSchema.userId))),
pg : 'SELECT "staging"."user"."name", "dev"."post"."content" FROM "staging"."user" INNER JOIN "dev"."post" ON ("staging"."user"."id" = "dev"."post"."userId")',
sqlite: 'SELECT "staging"."user"."name", "dev"."post"."content" FROM "staging"."user" INNER JOIN "dev"."post" ON ("staging"."user"."id" = "dev"."post"."userId")',
mysql : 'SELECT `staging`.`user`.`name`, `dev`.`post`.`content` FROM `staging`.`user` INNER JOIN `dev`.`post` ON (`staging`.`user`.`id` = `dev`.`post`.`userId`)'
});
Harness.test({
query : uws.select(uws.name, postWithSchema.content).from(uws.join(postWithSchema).on(uws.id.equals(postWithSchema.userId))),
pg : 'SELECT "uws"."name", "dev"."post"."content" FROM "staging"."user" AS "uws" INNER JOIN "dev"."post" ON ("uws"."id" = "dev"."post"."userId")',
sqlite: 'SELECT "uws"."name", "dev"."post"."content" FROM "staging"."user" AS "uws" INNER JOIN "dev"."post" ON ("uws"."id" = "dev"."post"."userId")',
mysql : 'SELECT `uws`.`name`, `dev`.`post`.`content` FROM `staging`.`user` AS `uws` INNER JOIN `dev`.`post` ON (`uws`.`id` = `dev`.`post`.`userId`)'
});