@@ -11,6 +11,97 @@ describe('compilation errors', () => {
1111 ] ) ;
1212 } ) ;
1313
14+ test ( 'not selecting from anything' , ( ) => {
15+ expect ( compilationErrorsForSingleStream ( 'SELECT 1, 2, 3' ) ) . toStrictEqual ( [
16+ {
17+ message : 'Must have a result column selecting from a table' ,
18+ source : 'SELECT 1, 2, 3'
19+ }
20+ ] ) ;
21+ } ) ;
22+
23+ test ( 'selecting table-valued function' , ( ) => {
24+ expect ( compilationErrorsForSingleStream ( "SELECT * FROM json_each(auth.parameter('x'))" ) ) . toStrictEqual ( [
25+ {
26+ message : 'Sync streams can only select from actual tables' ,
27+ source : '*'
28+ } ,
29+ {
30+ message : 'Must have a result column selecting from a table' ,
31+ source : "SELECT * FROM json_each(auth.parameter('x'))"
32+ }
33+ ] ) ;
34+ } ) ;
35+
36+ test ( 'join with using' , ( ) => {
37+ expect ( compilationErrorsForSingleStream ( 'SELECT u.* FROM users u INNER JOIN orgs USING (org_id)' ) ) . toStrictEqual ( [
38+ {
39+ message : 'USING is not supported' ,
40+ source : 'SELECT u.* FROM users u INNER JOIN orgs USING (org_id)'
41+ }
42+ ] ) ;
43+ } ) ;
44+
45+ test ( 'selecting connection value' , ( ) => {
46+ expect ( compilationErrorsForSingleStream ( "SELECT u.*, auth.parameter('x') FROM users u;" ) ) . toStrictEqual ( [
47+ {
48+ message : 'This attempts to sync a connection parameter. Only values from the source database can be synced.' ,
49+ source : "auth.parameter('x')"
50+ }
51+ ] ) ;
52+ } ) ;
53+
54+ test ( 'selecting from multiple tables' , ( ) => {
55+ expect (
56+ compilationErrorsForSingleStream (
57+ 'SELECT u.*, orgs.* FROM users u INNER JOIN orgs ON u.id = auth.user_id() AND u.org = orgs.id'
58+ )
59+ ) . toStrictEqual ( [
60+ {
61+ message : "Sync streams can only select from a single table, and this one already selects from 'users'." ,
62+ source : 'orgs.*'
63+ }
64+ ] ) ;
65+ } ) ;
66+
67+ test ( 'subexpressions from different rows' , ( ) => {
68+ expect (
69+ compilationErrorsForSingleStream (
70+ "SELECT u.* FROM users u INNER JOIN orgs WHERE u.name || orgs.name = subscription.parameter('a')"
71+ )
72+ ) . toStrictEqual ( [
73+ {
74+ message :
75+ "This expression already references 'users', so it can't also reference data from this row unless the two are compared with an equals operator." ,
76+ source : 'orgs.name'
77+ }
78+ ] ) ;
79+ } ) ;
80+
81+ test ( 'ambigious reference' , ( ) => {
82+ expect (
83+ compilationErrorsForSingleStream ( 'SELECT u.* FROM users u INNER JOIN orgs ON u.org = orgs.id WHERE is_public' )
84+ ) . toStrictEqual ( [
85+ {
86+ message : 'Invalid unqualified reference since multiple tables are in scope' ,
87+ source : 'is_public'
88+ }
89+ ] ) ;
90+ } ) ;
91+
92+ test ( 'table that has not been added' , ( ) => {
93+ expect ( compilationErrorsForSingleStream ( 'SELECT users.* FROM orgs;' ) ) . toStrictEqual ( [
94+ {
95+ message : "Table 'users' has not been added in a FROM clause here." ,
96+ source : 'users.*'
97+ } ,
98+ {
99+ message : 'Must have a result column selecting from a table' ,
100+ source : 'SELECT users.* FROM orgs'
101+ }
102+ ] ) ;
103+ } ) ;
104+
14105 test ( 'IN operator with static left clause' , ( ) => {
15106 expect (
16107 compilationErrorsForSingleStream ( "SELECT * FROM issues WHERE 'static' IN (SELECT id FROM users WHERE is_admin)" )
@@ -78,4 +169,40 @@ describe('compilation errors', () => {
78169 { message : 'Invalid schema in function name' , source : 'request.user_id' }
79170 ] ) ;
80171 } ) ;
172+
173+ test ( 'full join' , ( ) => {
174+ expect ( compilationErrorsForSingleStream ( 'select i.* from issues i FULL JOIN users u' ) ) . toStrictEqual ( [
175+ { message : 'FULL JOIN is not supported' , source : 'select i.* from issues i FULL JOIN users u' }
176+ ] ) ;
177+ } ) ;
178+
179+ test ( 'subquery star' , ( ) => {
180+ expect ( compilationErrorsForSingleStream ( 'select * from users where org in (select * from orgs)' ) ) . toStrictEqual ( [
181+ { message : 'Must return a single expression column' , source : 'select * from orgs' }
182+ ] ) ;
183+ } ) ;
184+
185+ test ( 'filter star' , ( ) => {
186+ expect ( compilationErrorsForSingleStream ( 'select * from users where users.*' ) ) . toStrictEqual ( [
187+ { message : '* columns are not supported here' , source : 'users.*' }
188+ ] ) ;
189+ } ) ;
190+
191+ test ( 'request parameter wrong count' , ( ) => {
192+ expect (
193+ compilationErrorsForSingleStream ( "select * from users where id = auth.parameter('foo', 'bar')" )
194+ ) . toStrictEqual ( [ { message : 'Expected a single argument here' , source : 'auth.parameter' } ] ) ;
195+ } ) ;
196+
197+ test ( 'user_id on wrong schema' , ( ) => {
198+ expect ( compilationErrorsForSingleStream ( 'select * from users where id = subscription.user_id()' ) ) . toStrictEqual ( [
199+ { message : '.user_id() is only available on auth schema' , source : 'subscription.user_id' }
200+ ] ) ;
201+ } ) ;
202+
203+ test ( 'unknown request function' , ( ) => {
204+ expect ( compilationErrorsForSingleStream ( 'select * from users where id = subscription.whatever()' ) ) . toStrictEqual ( [
205+ { message : 'Unknown request function' , source : 'subscription.whatever' }
206+ ] ) ;
207+ } ) ;
81208} ) ;
0 commit comments