Skip to content

Commit 60ad43a

Browse files
committed
Successful first run on major revamp
1 parent ef9a0ca commit 60ad43a

26 files changed

Lines changed: 572 additions & 575 deletions

src/clients/abstracts/AbstractSQLClient.js

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { SimpleEmitter } from './SimpleEmitter.js';
2+
3+
export class LinkedQLClient extends SimpleEmitter {
4+
5+
#dialect;
6+
#options;
7+
8+
#capabilityOverride;
9+
#workingCapability;
10+
11+
get dialect() { return this.#dialect; }
12+
get options() { return this.#options; }
13+
14+
constructor({ dialect, capability = {}, ...options } = {}) {
15+
super();
16+
17+
this.#dialect = dialect;
18+
this.#options = options;
19+
20+
this.#capabilityOverride = capability;
21+
this.#workingCapability = capability;
22+
}
23+
24+
async connect() { }
25+
26+
async disconnect() { }
27+
28+
async setCapability(capMap) {
29+
const _capMap = Object.fromEntries(
30+
Object.entries(capMap).filter(([k, v]) => {
31+
return !v || this.#capabilityOverride[k] !== false;
32+
})
33+
);
34+
35+
// Publish...
36+
this.#workingCapability = {
37+
...this.#workingCapability,
38+
..._capMap,
39+
};
40+
41+
// realtime?
42+
if (_capMap.realtime === false) {
43+
await this._teardownRealtime?.();
44+
} else if (_capMap.realtime) {
45+
await this._setupRealtime?.();
46+
}
47+
48+
return _capMap;
49+
}
50+
51+
// ------------
52+
53+
#lifetimeSchemaInference;
54+
55+
resolveGetResolver(cb) {
56+
if (this.#options.nonDDLMode) {
57+
// We've been promised no DDL operations will
58+
// happen while we're running
59+
if (!this.#lifetimeSchemaInference)
60+
this.#lifetimeSchemaInference = cb();
61+
return this.#lifetimeSchemaInference;
62+
}
63+
return cb();
64+
}
65+
}

src/clients/abstracts/MainstreamSQLClient.js renamed to src/clients/abstracts/MainstreamDBClient.js

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,59 @@
1-
import { AbstractSQLClient } from './AbstractSQLClient.js';
1+
import { LinkedQLClient } from './LinkedQLClient.js';
22
import { RealtimeClient } from '../../proc/realtime/RealtimeClient.js';
33
import { SchemaInference } from './SchemaInference.js';
44
import { SyncEngine } from '../../proc/sync/SyncEngine.js';
55
import { SQLParser } from '../../lang/SQLParser.js';
6+
import { registry } from '../../lang/registry.js';
67
import { normalizeQueryArgs } from './util.js';
78
import { Result } from '../Result.js';
8-
import { registry } from '../../lang/registry.js';
99

10-
export class MainstreamSQLClient extends AbstractSQLClient {
10+
export class MainstreamDBClient extends LinkedQLClient {
11+
12+
// Standard getters: parsers, resolver, sync
1113

1214
#parser;
1315
#sync;
14-
#realtimeClient;
1516

1617
get parser() { return this.#parser; }
18+
get resolver() {
19+
return super.resolveGetResolver(() =>
20+
new SchemaInference({ client: this }));
21+
}
1722
get sync() { return this.#sync; }
18-
get realtimeClient() { return this.#realtimeClient; }
1923

20-
async connect() {
21-
if (this.#parser) return;
24+
// Internal
25+
26+
#realtimeClient;
27+
28+
// ------------
29+
30+
constructor(options) {
31+
super(options);
2232

2333
this.#parser = new SQLParser({ dialect: this.dialect });
2434
this.#sync = new SyncEngine({
25-
dialect: this.dialect,
2635
drainMode: 'drain',
2736
lifecycleHook: async (status) => {
2837
await this.setCapability({ realtime: !!status });
2938
}
3039
});
3140

3241
this.#realtimeClient = new RealtimeClient(this);
33-
await super.connect();
3442
}
3543

3644
async disconnect() {
37-
await super.disconnect();
3845
await this.#sync.close({ destroy: true });
46+
await super.disconnect();
3947
}
4048

41-
async setCapability(capMap) {
42-
capMap = await super.setCapability(capMap);
43-
// realtime?
44-
if (capMap.realtime === false) {
45-
await this._teardownRealtime();
46-
} else if (capMap.realtime) {
47-
await this._setupRealtime();
48-
}
49-
return capMap;
50-
}
51-
52-
#lifetimeSchemaInference;
53-
54-
createSchemaInference() {
55-
if (this.options.nonDDLMode) {
56-
// We've been promised no DDL operations will
57-
// happen while we're running
58-
if (!this.#lifetimeSchemaInference)
59-
this.#lifetimeSchemaInference = new SchemaInference({ client: this });
60-
return this.#lifetimeSchemaInference;
61-
}
62-
return new SchemaInference({ client: this });
63-
}
49+
// ------------
6450

6551
async query(...args) {
6652
const [_query, options] = normalizeQueryArgs(...args);
6753
const query = await this.#parser.parse(_query, options);
6854

6955
const resolveQuery = async (query, tx = null) => {
70-
const schemaInference = this.createSchemaInference();
56+
const schemaInference = this.resolver;
7157
return await schemaInference.resolveQuery(query, { tx });
7258
};
7359

@@ -104,7 +90,7 @@ export class MainstreamSQLClient extends AbstractSQLClient {
10490
const [_query, options] = normalizeQueryArgs(...args);
10591
const query = await this.#parser.parse(_query, options);
10692

107-
const schemaInference = this.createSchemaInference();
93+
const schemaInference = this.resolver;
10894
const resolvedQuery = await schemaInference.resolveQuery(query, options);
10995

11096
return await this._stream(resolvedQuery, options);

src/clients/edge/Abstract1EdgeClient.js

Lines changed: 0 additions & 167 deletions
This file was deleted.

0 commit comments

Comments
 (0)