forked from adelsz/pgtyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
autoinsert trailing commas in embedded SQL blocks
- Loading branch information
Showing
5 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`inserts trailing semicolon when needed 1`] = ` | ||
Object { | ||
"events": Array [], | ||
"queries": Array [ | ||
Object { | ||
"name": "FindBookById", | ||
"params": Array [ | ||
Object { | ||
"codeRefs": Object { | ||
"used": Array [ | ||
Object { | ||
"a": 61, | ||
"b": 62, | ||
"col": 36, | ||
"line": 2, | ||
}, | ||
], | ||
}, | ||
"name": "id", | ||
"required": false, | ||
"transform": Object { | ||
"type": "scalar", | ||
}, | ||
}, | ||
], | ||
"statement": Object { | ||
"body": "SELECT * FROM books WHERE id = :id", | ||
"loc": Object { | ||
"a": 29, | ||
"b": 62, | ||
"col": 4, | ||
"line": 2, | ||
}, | ||
}, | ||
"usedParamSet": Object { | ||
"id": true, | ||
}, | ||
}, | ||
Object { | ||
"name": "FindBooks", | ||
"params": Array [], | ||
"statement": Object { | ||
"body": "SELECT * FROM books", | ||
"loc": Object { | ||
"a": 92, | ||
"b": 110, | ||
"col": 4, | ||
"line": 5, | ||
}, | ||
}, | ||
"usedParamSet": Object {}, | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`parser finds string template in correct file 1`] = ` | ||
Object { | ||
"events": Array [], | ||
"queries": Array [ | ||
Object { | ||
"name": "FindBookById", | ||
"params": Array [ | ||
Object { | ||
"codeRefs": Object { | ||
"used": Array [ | ||
Object { | ||
"a": 61, | ||
"b": 62, | ||
"col": 36, | ||
"line": 2, | ||
}, | ||
], | ||
}, | ||
"name": "id", | ||
"required": false, | ||
"transform": Object { | ||
"type": "scalar", | ||
}, | ||
}, | ||
], | ||
"statement": Object { | ||
"body": "SELECT * FROM books WHERE id = :id", | ||
"loc": Object { | ||
"a": 29, | ||
"b": 62, | ||
"col": 4, | ||
"line": 2, | ||
}, | ||
}, | ||
"usedParamSet": Object { | ||
"id": true, | ||
}, | ||
}, | ||
], | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { parseCode } from './parseRescript.js'; | ||
|
||
test('parser finds string template in correct file', () => { | ||
const fileContent = ` | ||
let query = %sql.one(\` | ||
/* @name FindBookById */ | ||
SELECT * FROM books WHERE id = :id; | ||
\`); | ||
`; | ||
|
||
const result = parseCode(fileContent); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('inserts trailing semicolon when needed', () => { | ||
const fileContent = ` | ||
let query = %sql.one(\` | ||
/* @name FindBookById */ | ||
SELECT * FROM books WHERE id = :id | ||
\`); | ||
let queryMany = %sql.many(\` | ||
/* @name FindBooks */ | ||
SELECT * FROM books | ||
\`); | ||
`; | ||
|
||
const result = parseCode(fileContent); | ||
expect(result).toMatchSnapshot(); | ||
}); |