-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.ts
48 lines (46 loc) · 1.06 KB
/
sample.ts
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
import { expect } from 'chai'
import { generateSQL } from '../src/code-gen'
import { decode } from '../src/parse'
let text = /* sql */ `
select post [
id as post_id
title
author_id
user as author { nickname, avatar } where delete_time is null
type_id
post_type {
name as type
is_hidden
} where is_hidden = 0 or user.is_admin = 1
] where created_at >= :since
and delete_time is null
and title like :keyword
order by created_at desc
limit 25
`
let ast = decode(text)
let query = generateSQL(ast)
let sql = /* sql */ `
select
post.id as post_id
, post.title
, post.author_id
, author.nickname
, author.avatar
, post.type_id
, post_type.name as type
, post_type.is_hidden
from post
inner join user as author on author.id = post.author_id
inner join post_type on post_type.id = post.post_type_id
where author.delete_time is null
and (post_type.is_hidden = 0
or user.is_admin = 1)
and post.created_at >= :since
and post.delete_time is null
and post.title like :keyword
order by
post.created_at desc
limit 25
`
expect(query).to.equals(sql)