Skip to content

Commit 212d41e

Browse files
committed
hasContext
1 parent 55a4131 commit 212d41e

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/sql/sql-query/sql-query.spec.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import {
1616
RefName,
17+
sql,
1718
SqlCase,
1819
SqlColumn,
1920
SqlColumnList,
@@ -569,29 +570,27 @@ describe('SqlQuery', () => {
569570
});
570571
});
571572

572-
describe('#getContext', () => {
573+
describe('#hasContext / #getContext', () => {
573574
it('works with nothing', () => {
574-
expect(
575-
SqlQuery.parse(
576-
sane`
577-
SELECT *
578-
FROM wikipedia
579-
`,
580-
).getContext(),
581-
).toEqual({});
575+
const query = sql`
576+
SELECT *
577+
FROM wikipedia
578+
` as SqlQuery;
579+
580+
expect(query.hasContext()).toEqual(false);
581+
expect(query.getContext()).toEqual({});
582582
});
583583

584584
it('works with something', () => {
585-
expect(
586-
SqlQuery.parse(
587-
sane`
588-
SET b = 2;
589-
SET c = 'hello';
590-
SELECT *
591-
FROM wikipedia;
592-
`,
593-
).getContext(),
594-
).toEqual({
585+
const query = sql`
586+
SET b = 2;
587+
SET c = 'hello';
588+
SELECT *
589+
FROM wikipedia;
590+
` as SqlQuery;
591+
592+
expect(query.hasContext()).toEqual(true);
593+
expect(query.getContext()).toEqual({
595594
b: 2,
596595
c: 'hello',
597596
});

src/sql/sql-query/sql-query.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ export class SqlQuery extends SqlExpression {
355355
return SqlBase.fromValue(value);
356356
}
357357

358+
public hasContext(): boolean {
359+
return Boolean(this.contextStatements);
360+
}
361+
358362
public getContext(): Record<string, any> {
359363
return SqlSetStatement.contextStatementsToContext(this.contextStatements?.values);
360364
}

src/sql/sql-with-query/sql-with-query.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ export class SqlWithQuery extends SqlExpression {
178178
return SqlBase.fromValue(value);
179179
}
180180

181+
public hasContext(): boolean {
182+
return Boolean(this.contextStatements);
183+
}
184+
181185
public getContext(): Record<string, any> {
182186
return SqlSetStatement.contextStatementsToContext(this.contextStatements?.values);
183187
}

0 commit comments

Comments
 (0)