Skip to content

Commit

Permalink
support quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexErrant committed Dec 14, 2023
1 parent b132935 commit c96b275
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/src/query2sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ test('not a', () => {
)
})

test('QuotedString is fts', () => {
const actual = convert('"a b"')
expect(actual).toEqual(
`(noteFtsFv.rowid IN (SELECT rowid FROM noteFtsFv WHERE noteFtsFv.fieldValues MATCH '"a b"'))`,
)
})

test('2 SimpleStrings are ANDed', () => {
const actual = convert('a b')
expect(actual).toEqual(
Expand Down
6 changes: 3 additions & 3 deletions app/src/query2sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export function convert(input: string) {
}

function astEnter(input: string, node: SyntaxNodeRef, context: Context) {
if (node.name === 'SimpleString') {
if (node.name === 'SimpleString' || node.name === 'QuotedString') {
const separator = andOrNothing(node.node)
if (separator !== '') context.current.attach({ type: separator })
const value = input.slice(node.from, node.to)
const negate = isNegated(node.node)
context.current.attach({ type: 'SimpleString', value, negate })
context.current.attach({ type: node.name, value, negate })
} else if (node.name === 'ParenthesizedExpression') {
const negate = isNegated(node.node)
const group = new Group(context.current, negate)
Expand All @@ -61,7 +61,7 @@ function astLeave(_input: string, node: SyntaxNodeRef, context: Context) {

function serialize(node: Node, context: Context) {
const spaces = ' '.repeat(context.indent)
if (node.type === 'SimpleString') {
if (node.type === 'SimpleString' || node.type === 'QuotedString') {
const query = `(noteFtsFv.rowid ${
node.negate ? 'NOT ' : ''
}IN (SELECT rowid FROM noteFtsFv WHERE noteFtsFv.fieldValues MATCH '${
Expand Down

0 comments on commit c96b275

Please sign in to comment.