@nongt/visql-core 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import type { DerivedQuery, JoinClause, TableFrom } from './queryAst.js';
2
- export declare const binaryOperators: readonly ["=", "!=", "<", "<=", ">", ">=", "LIKE", "IN", "BETWEEN", "REGEXP", "IS NULL", "IS NOT NULL"];
2
+ export declare const binaryOperators: readonly ["=", "!=", "IS NOT DISTINCT FROM", "<", "<=", ">", ">=", "LIKE", "IN", "BETWEEN", "REGEXP", "IS NULL", "IS NOT NULL"];
3
3
  export type BinaryOperator = typeof binaryOperators[number];
4
4
  /** The operators that take no right-hand side. */
5
5
  export declare const unaryOperators: readonly ["IS NULL", "IS NOT NULL"];
@@ -1,6 +1,12 @@
1
1
  import type { LiteralValue, RelativeDate } from './ast.js';
2
2
  import { type QueryPipeline } from './queryAst.js';
3
3
  import { type DatabaseColumnType, type DatabaseSchema } from './schema.js';
4
+ /** A column a param is compared with: the schema's table name, never the
5
+ * query's alias. */
6
+ export interface ParamColumn {
7
+ table: string;
8
+ column: string;
9
+ }
4
10
  /** A param the query needs, and the type of the column it's compared
5
11
  * against — undefined when it isn't compared against a known column, or is
6
12
  * compared against columns of different types (see conflictingParams). */
@@ -11,6 +17,10 @@ export interface QueryParam {
11
17
  * computes its value — "today" in its user's time zone, its first day of
12
18
  * the week, the form a dateTime column needs (`type`). */
13
19
  relative?: RelativeDate;
20
+ /** The column it's compared with, when that's one column of the schema
21
+ * (any number of times): e.g. to offer the column's `options` as its
22
+ * values. Not from a LIKE or REGEXP, whose value is a pattern. */
23
+ column?: ParamColumn;
14
24
  }
15
25
  /** The params `query` needs a value for, in the order they first appear —
16
26
  * what an application asks for before running a saved query (and the only
@@ -24,6 +24,11 @@ export interface SpanMarks {
24
24
  /** Writes with `marks` recording where each part goes (from the query as
25
25
  * it's written: buildSql starts it). */
26
26
  export declare function writeMarked<T>(marks: SpanMarks, write: () => T): T;
27
+ /** How `IS NOT DISTINCT FROM` is written (issue 217). `'native'`:
28
+ * `IS NOT DISTINCT FROM`, MySQL's `<=>`. `'expanded'`: `(a = b OR (a IS
29
+ * NULL AND b IS NULL))`, the same rows in any database, for SQL Server
30
+ * before 2022, which has no IS NOT DISTINCT FROM. */
31
+ export type NullSafeEqual = 'native' | 'expanded';
27
32
  export declare function astToWhereClause(ast: ExpressionNode, dialect: SqlDialect, params?: SqlParams): string;
28
33
  export declare function formatFromClause(from: FromClause, dialect: SqlDialect, params?: SqlParams): string;
29
34
  export declare function formatJoinClause(join: JoinClause, dialect: SqlDialect, params?: SqlParams): string;
@@ -59,6 +64,8 @@ export declare function astToSql(pipeline: QueryPipeline, dialect: SqlDialect, o
59
64
  /** The schema the query is built on: a value compared with a column
60
65
  * that has a `format` is written in it (see ParameterizedSqlOptions). */
61
66
  schema?: DatabaseSchema;
67
+ /** How a null-safe equal is written (see ParameterizedSqlOptions). */
68
+ nullSafeEqual?: NullSafeEqual;
62
69
  }): string;
63
70
  /** SQL with its values as bound parameters, for executing it. */
64
71
  export interface ParameterizedSql {
@@ -91,6 +98,9 @@ export interface ParameterizedSqlOptions {
91
98
  * — a param's value from `values` too. Without it, values are written
92
99
  * the query's own way (a time `HH:MM:SS`). */
93
100
  schema?: DatabaseSchema;
101
+ /** How `IS NOT DISTINCT FROM` is written: `'native'` (default), or
102
+ * `'expanded'` into `=` and IS NULL for SQL Server before 2022. */
103
+ nullSafeEqual?: NullSafeEqual;
94
104
  }
95
105
  /** The query as SQL whose values — in WHERE, JOIN ON and SELECT, including
96
106
  * inside functions, IF/CASE and IN lists — are bound parameters rather than
@@ -9,11 +9,11 @@ export { SharedBaseError, addSharedQuery, joinSharedQuery, makeShared, makeSubQu
9
9
  export { joinMultiplicity, repeatedReads, repeatedTables, rowsPerBase, type JoinMultiplicity, } from './core/fanOut.js';
10
10
  export { ScopeError, scopeQuery, unscopedBodies, type ScopeRule, } from './core/scopeQuery.js';
11
11
  export { addCondition, addGroupBy, addJoin, addOrderBy, addSelectItem, expr, removeJoin, requireBaseTable, setBaseTable, setDistinct, setHaving, setPaging, } from './core/queryHelpers.js';
12
- export { queryParams, type QueryParam } from './core/params.js';
12
+ export { queryParams, type ParamColumn, type QueryParam } from './core/params.js';
13
13
  export { relativeDateLabel } from './core/relativeDates.js';
14
14
  export { QUERY_FORMAT_VERSION, QueryFormatError, loadQuery, saveQuery, type StoredQuery, } from './core/storedQuery.js';
15
15
  export type { ResolveName } from './core/resolveNames.js';
16
- export { astToParameterizedSql, astToSql, DIALECTS, DIALECT_LABELS, type ParameterizedSql, type ParameterizedSqlOptions, type SqlDialect, } from './core/sqlGen.js';
16
+ export { astToParameterizedSql, astToSql, DIALECTS, DIALECT_LABELS, type NullSafeEqual, type ParameterizedSql, type ParameterizedSqlOptions, type SqlDialect, } from './core/sqlGen.js';
17
17
  export { EMPTY_SCHEMA, filterSchema, validateSchema, type DatabaseColumnType, type DatabaseSchema, type ColumnOption, type Relation, type SchemaIssue, type SchemaIssueKind, type Table, type TableColumn, type TableGroup, } from './core/schema.js';
18
18
  export { QUERY_ISSUE_KINDS, QUERY_WARNING_KINDS, validateQuery, type QueryIssue, type QueryIssueKind, type QueryWarningKind, type QueryIssueSeverity, type ValidateQueryOptions, } from './core/queryValidation.js';
19
19
  export { default as issueLocation, type IssueLocationStep } from './core/issueLocation.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nongt/visql-core",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "The query logic of @nongt/visql, for a backend: load, check, scope, write SQL, import SQL. No React, no dependencies.",
5
5
  "keywords": [
6
6
  "sql",