@eltjs/elt-sqlserver 0.0.0-stage → 0.10.1
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.
- package/LICENSE +202 -0
- package/README.md +485 -2
- package/dist/computed-dataset.d.ts +31 -0
- package/dist/computed-dataset.js +380 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +10 -0
- package/dist/sql-server-append-writer.d.ts +8 -0
- package/dist/sql-server-append-writer.js +13 -0
- package/dist/sql-server-as-of.d.ts +14 -0
- package/dist/sql-server-as-of.js +44 -0
- package/dist/sql-server-checkpoint-store.d.ts +10 -0
- package/dist/sql-server-checkpoint-store.js +101 -0
- package/dist/sql-server-column.d.ts +53 -0
- package/dist/sql-server-column.js +295 -0
- package/dist/sql-server-columns.d.ts +15 -0
- package/dist/sql-server-columns.js +49 -0
- package/dist/sql-server-connection.d.ts +6 -0
- package/dist/sql-server-connection.js +56 -0
- package/dist/sql-server-deduplicating-writer.d.ts +18 -0
- package/dist/sql-server-deduplicating-writer.js +102 -0
- package/dist/sql-server-dependents.d.ts +9 -0
- package/dist/sql-server-dependents.js +54 -0
- package/dist/sql-server-derived-status.d.ts +9 -0
- package/dist/sql-server-derived-status.js +60 -0
- package/dist/sql-server-descriptions.d.ts +6 -0
- package/dist/sql-server-descriptions.js +53 -0
- package/dist/sql-server-destination.d.ts +32 -0
- package/dist/sql-server-destination.js +95 -0
- package/dist/sql-server-failure-type.d.ts +2 -0
- package/dist/sql-server-failure-type.js +25 -0
- package/dist/sql-server-file-store.d.ts +21 -0
- package/dist/sql-server-file-store.js +91 -0
- package/dist/sql-server-fit.d.ts +20 -0
- package/dist/sql-server-fit.js +52 -0
- package/dist/sql-server-history.d.ts +15 -0
- package/dist/sql-server-history.js +148 -0
- package/dist/sql-server-identifiers.d.ts +10 -0
- package/dist/sql-server-identifiers.js +27 -0
- package/dist/sql-server-indexes.d.ts +23 -0
- package/dist/sql-server-indexes.js +121 -0
- package/dist/sql-server-load.d.ts +19 -0
- package/dist/sql-server-load.js +58 -0
- package/dist/sql-server-numbering.d.ts +32 -0
- package/dist/sql-server-numbering.js +255 -0
- package/dist/sql-server-overwrite-deduplicating-writer.d.ts +4 -0
- package/dist/sql-server-overwrite-deduplicating-writer.js +8 -0
- package/dist/sql-server-overwrite-writer.d.ts +4 -0
- package/dist/sql-server-overwrite-writer.js +9 -0
- package/dist/sql-server-parts-table.d.ts +24 -0
- package/dist/sql-server-parts-table.js +167 -0
- package/dist/sql-server-passes.d.ts +6 -0
- package/dist/sql-server-passes.js +71 -0
- package/dist/sql-server-reader-view.d.ts +12 -0
- package/dist/sql-server-reader-view.js +71 -0
- package/dist/sql-server-rule-columns.d.ts +12 -0
- package/dist/sql-server-rule-columns.js +69 -0
- package/dist/sql-server-schemas.d.ts +4 -0
- package/dist/sql-server-schemas.js +8 -0
- package/dist/sql-server-setup-error.d.ts +3 -0
- package/dist/sql-server-setup-error.js +6 -0
- package/dist/sql-server-sync-history-schema.d.ts +7 -0
- package/dist/sql-server-sync-history-schema.js +120 -0
- package/dist/sql-server-sync-history.d.ts +14 -0
- package/dist/sql-server-sync-history.js +165 -0
- package/dist/sql-server-table.d.ts +10 -0
- package/dist/sql-server-table.js +40 -0
- package/dist/sql-server-views.d.ts +7 -0
- package/dist/sql-server-views.js +70 -0
- package/dist/sql-server-writer.d.ts +40 -0
- package/dist/sql-server-writer.js +914 -0
- package/dist/view.d.ts +23 -0
- package/dist/view.js +82 -0
- package/package.json +48 -4
package/dist/view.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Connection, DerivedDataset, type PipelineClock } from '@eltjs/elt';
|
|
2
|
+
import { SqlServerDestination } from './sql-server-destination.ts';
|
|
3
|
+
import type { SqlServerTable } from './sql-server-table.ts';
|
|
4
|
+
export declare class View extends DerivedDataset<SqlServerTable> {
|
|
5
|
+
#private;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly into: SqlServerDestination;
|
|
8
|
+
constructor({ into, name, description, columns, sql, }: {
|
|
9
|
+
into: SqlServerDestination;
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
columns: Readonly<Record<string, string>>;
|
|
13
|
+
sql: string;
|
|
14
|
+
});
|
|
15
|
+
get qualifiedName(): string;
|
|
16
|
+
validate(connections: readonly Connection<SqlServerTable>[]): void;
|
|
17
|
+
refresh({ connections, earlier, clock, }: {
|
|
18
|
+
readonly connections: readonly Connection<SqlServerTable>[];
|
|
19
|
+
readonly earlier: readonly DerivedDataset<SqlServerTable>[];
|
|
20
|
+
readonly clock: PipelineClock;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export declare function made(connections: readonly Connection<SqlServerTable>[], into: SqlServerDestination): Set<string>;
|
package/dist/view.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { DerivedDataset, refreshView, } from '@eltjs/elt';
|
|
2
|
+
import { connect, transaction } from './sql-server-connection.js';
|
|
3
|
+
import { numberOf } from './sql-server-dependents.js';
|
|
4
|
+
import { SqlServerDerivedStatus } from './sql-server-derived-status.js';
|
|
5
|
+
import { SqlServerDestination, database } from './sql-server-destination.js';
|
|
6
|
+
import { identifiers } from './sql-server-identifiers.js';
|
|
7
|
+
import { marts, warehouse } from './sql-server-schemas.js';
|
|
8
|
+
import { publishViews, withdrawView, } from './sql-server-views.js';
|
|
9
|
+
// The error of a relation that no schema has: CREATE VIEW over it fails with
|
|
10
|
+
// it. A relation that goes away after the view was made fails each read of
|
|
11
|
+
// the view with 4413 instead (ADR 0006).
|
|
12
|
+
const invalidObject = 208;
|
|
13
|
+
// A view over what the pipeline loads into one SQL Server database: derived
|
|
14
|
+
// data that SQL Server computes on each read, as a dbt model materialized as
|
|
15
|
+
// a view is. It lives in marts, where its SQL's bare names resolve first, and
|
|
16
|
+
// then in dbo, so it reads reader views. Its inputs are the relations its
|
|
17
|
+
// SQL reads, so it names none of them. It appears, or waits, as refreshView
|
|
18
|
+
// of elt says.
|
|
19
|
+
export class View extends DerivedDataset {
|
|
20
|
+
name;
|
|
21
|
+
// The database the view lives in, where a computed dataset after it reads
|
|
22
|
+
// it.
|
|
23
|
+
into;
|
|
24
|
+
#view;
|
|
25
|
+
constructor({ into, name, description, columns, sql, }) {
|
|
26
|
+
super();
|
|
27
|
+
this.name = name;
|
|
28
|
+
this.into = into;
|
|
29
|
+
this.#view = { name, description, columns, query: sql };
|
|
30
|
+
Object.freeze(this);
|
|
31
|
+
}
|
|
32
|
+
get qualifiedName() {
|
|
33
|
+
return `${marts}.${this.name}`;
|
|
34
|
+
}
|
|
35
|
+
validate(connections) {
|
|
36
|
+
if (made(connections, this.into).has(identifiers.key(this.qualifiedName)))
|
|
37
|
+
throw new TypeError(`View ${this.qualifiedName} has the name of a table or reader view a copy makes`);
|
|
38
|
+
}
|
|
39
|
+
async refresh({ connections, earlier, clock, }) {
|
|
40
|
+
await using connection = await connect(this.into[database]);
|
|
41
|
+
await refreshView({
|
|
42
|
+
publish: () => transaction(connection, () => publishViews(connection, [this.#view])),
|
|
43
|
+
missing: missingRelation,
|
|
44
|
+
awaited: new Set([
|
|
45
|
+
...made(connections, this.into),
|
|
46
|
+
...earlier.flatMap((dataset) => derivedRelation(dataset) ?? []),
|
|
47
|
+
]),
|
|
48
|
+
withdraw: () => transaction(connection, () => withdrawView(connection, this.name)),
|
|
49
|
+
status: new SqlServerDerivedStatus(connection, this.qualifiedName, 'view', clock),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// The schema-qualified relation that SQL Server found missing, in lower case,
|
|
54
|
+
// as the database compares names, with a bare name resolved in marts, where
|
|
55
|
+
// the view's SQL reads bare names from first. The message names the relation
|
|
56
|
+
// without brackets, as [_warehouse].[raw_x] gives '_warehouse.raw_x' (probe
|
|
57
|
+
// of 2026-11-20).
|
|
58
|
+
function missingRelation(error) {
|
|
59
|
+
if (numberOf(error) !== invalidObject || !Error.isError(error))
|
|
60
|
+
return undefined;
|
|
61
|
+
const name = /^Invalid object name '(.+)'\.$/.exec(error.message)?.[1];
|
|
62
|
+
if (name === undefined)
|
|
63
|
+
return undefined;
|
|
64
|
+
return identifiers.key(name.includes('.') ? name : `${marts}.${name}`);
|
|
65
|
+
}
|
|
66
|
+
// The reader views in marts and the raw tables in _warehouse that the
|
|
67
|
+
// pipeline's copies make in the database of into, schema-qualified and in
|
|
68
|
+
// lower case.
|
|
69
|
+
export function made(connections, into) {
|
|
70
|
+
const { location } = into[database];
|
|
71
|
+
return new Set(connections.flatMap(({ destination, steps }) => destination instanceof SqlServerDestination &&
|
|
72
|
+
destination[database].location === location
|
|
73
|
+
? steps.flatMap(({ to }) => [`${marts}.${to.name}`, `${warehouse}.${to.raw}`].map(identifiers.key))
|
|
74
|
+
: []));
|
|
75
|
+
}
|
|
76
|
+
// The relation that a derived dataset of this package makes for readers, in
|
|
77
|
+
// lower case.
|
|
78
|
+
function derivedRelation(dataset) {
|
|
79
|
+
return 'qualifiedName' in dataset && typeof dataset.qualifiedName === 'string'
|
|
80
|
+
? identifiers.key(dataset.qualifiedName)
|
|
81
|
+
: undefined;
|
|
82
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eltjs/elt-sqlserver",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.10.1",
|
|
4
|
+
"description": "The SQL Server destination of elt: each stream is a typed table in _warehouse, with a reader view in marts that the host names, numbered commits that readers read as of a position, and a checkpoint store and a sync history in the same database.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/ezzabuzaid/elt",
|
|
9
|
+
"directory": "packages/destinations/sqlserver"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ezzabuzaid/elt/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/ezzabuzaid/elt/tree/main/packages/destinations/sqlserver#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"elt",
|
|
17
|
+
"sql-server",
|
|
18
|
+
"azure-sql",
|
|
19
|
+
"mssql",
|
|
20
|
+
"destination",
|
|
21
|
+
"pipeline"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
"./package.json": "./package.json",
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"!dist/spec/**",
|
|
34
|
+
"!**/*.tsbuildinfo",
|
|
35
|
+
"!**/*.test.*"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@eltjs/elt": "^0.10.1",
|
|
42
|
+
"@eltjs/sdk-microsoft-sql-server": "^0.10.1",
|
|
43
|
+
"@zukhruf/async": "^0.8.51",
|
|
44
|
+
"@zukhruf/mutex": "^0.8.31",
|
|
45
|
+
"@zukhruf/vectors": "^0.8.51"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@zukhruf/testing": "^0.8.31"
|
|
49
|
+
}
|
|
50
|
+
}
|