@nongt/visql-core 0.6.1 → 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"];
@@ -113,6 +113,8 @@ export declare const DEFAULT_MESSAGES: {
113
113
  openUnionBranch: (table: string) => string;
114
114
  removeUnionBranch: (table: string) => string;
115
115
  joinTableGroup: string;
116
+ /** The heading over tables in no group, when others have one. */
117
+ otherTablesGroup: string;
116
118
  /** Free-form unions (issue 153): a new one, the query as one's first
117
119
  * query, another query for one, and a new query's canvas. */
118
120
  createUnion: string;
@@ -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
@@ -9,6 +9,13 @@ export interface Table {
9
9
  name: string;
10
10
  label: string;
11
11
  columns: TableColumn[];
12
+ /** The heading the table pickers list it under, such as its business
13
+ * area. Groups come in the order of their first table in the schema. */
14
+ group?: string;
15
+ /** A line under the label in the table pickers. The search matches it. */
16
+ description?: string;
17
+ /** Anything the host's own code needs about the table. Never read here. */
18
+ meta?: unknown;
12
19
  }
13
20
  export interface TableColumn {
14
21
  name: string;
@@ -75,6 +82,18 @@ export declare function filterSchema(schema: DatabaseSchema, tableFilter?: (tabl
75
82
  /** Every table in the schema, sorted by label — the canonical source for both
76
83
  * FieldView's column picker and FromFlowNode's table pickers. */
77
84
  export declare function allTables(schema: DatabaseSchema): Table[];
85
+ /** One heading's tables in a table picker: `group` undefined for the
86
+ * tables in no group. */
87
+ export interface TableGroup {
88
+ group: string | undefined;
89
+ tables: Table[];
90
+ }
91
+ /** `tables` as a table picker lists them (issue 245): the groups in the
92
+ * order of their first table in `order` (the whole schema, whose order the
93
+ * host decides, so every picker has its groups in the same order), the
94
+ * tables in each sorted by label, and the tables in no group last. With no
95
+ * group at all, one list sorted by label, as before. */
96
+ export declare function tableGroups(tables: readonly Table[], groupOf?: (table: Table) => string | undefined, order?: readonly Table[]): TableGroup[];
78
97
  export declare function findTable(schema: DatabaseSchema, name: string): Table | undefined;
79
98
  /** Every foreign key touching `tableName`, in either direction — whether it
80
99
  * holds the key or is referenced by one. */
@@ -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,12 +9,12 @@ 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';
17
- export { EMPTY_SCHEMA, filterSchema, validateSchema, type DatabaseColumnType, type DatabaseSchema, type ColumnOption, type Relation, type SchemaIssue, type SchemaIssueKind, type Table, type TableColumn, } from './core/schema.js';
16
+ export { astToParameterizedSql, astToSql, DIALECTS, DIALECT_LABELS, type NullSafeEqual, type ParameterizedSql, type ParameterizedSqlOptions, type SqlDialect, } from './core/sqlGen.js';
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';
20
20
  export { DEFAULT_FUNCTIONS, functionsForDialect, type ArgDef, type ArgKind, type FunctionRegistry, type FunctionSignature, } from './core/functionRegistry.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nongt/visql-core",
3
- "version": "0.6.1",
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",