@nymphjs/driver-postgresql 1.0.0-beta.12 → 1.0.0-beta.121

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,6 +1,6 @@
1
- import { Pool, PoolClient } from 'pg';
2
- import { NymphDriver, EntityConstructor, EntityInterface, FormattedSelector, Options, Selector } from '@nymphjs/nymph';
3
- import { PostgreSQLDriverConfig } from './conf';
1
+ import type { Pool, PoolClient } from 'pg';
2
+ import { NymphDriver, type EntityConstructor, type EntityObjectType, type EntityInterface, type EntityInstanceType, type SerializedEntityData, type FormattedSelector, type Options, type Selector } from '@nymphjs/nymph';
3
+ import { PostgreSQLDriverConfig } from './conf/index.js';
4
4
  type PostgreSQLDriverConnection = {
5
5
  client: PoolClient;
6
6
  done: () => void;
@@ -8,7 +8,11 @@ type PostgreSQLDriverConnection = {
8
8
  type PostgreSQLDriverTransaction = {
9
9
  connection: PostgreSQLDriverConnection | null;
10
10
  count: number;
11
+ latestPromise: Promise<any>;
11
12
  };
13
+ /**
14
+ * The PostgreSQL Nymph database driver.
15
+ */
12
16
  export default class PostgreSQLDriver extends NymphDriver {
13
17
  config: PostgreSQLDriverConfig;
14
18
  private postgresqlConfig;
@@ -18,55 +22,139 @@ export default class PostgreSQLDriver extends NymphDriver {
18
22
  protected transaction: PostgreSQLDriverTransaction | null;
19
23
  static escape(input: string): string;
20
24
  static escapeValue(input: string): string;
25
+ static escapeNullSequences(input: string): string;
26
+ static unescapeNullSequences(input: string): string;
27
+ static escapeNulls(input: string): string;
28
+ static unescapeNulls(input: string): string;
21
29
  constructor(config: Partial<PostgreSQLDriverConfig>, link?: Pool, transaction?: PostgreSQLDriverTransaction);
30
+ /**
31
+ * This is used internally by Nymph. Don't call it yourself.
32
+ *
33
+ * @returns A clone of this instance.
34
+ */
22
35
  clone(): PostgreSQLDriver;
23
36
  private getConnection;
37
+ /**
38
+ * Connect to the PostgreSQL database.
39
+ *
40
+ * @returns Whether this instance is connected to a PostgreSQL database.
41
+ */
24
42
  connect(): Promise<true>;
43
+ /**
44
+ * Disconnect from the PostgreSQL database.
45
+ *
46
+ * @returns Whether this instance is connected to a PostgreSQL database.
47
+ */
25
48
  disconnect(): Promise<false>;
26
49
  inTransaction(): Promise<boolean>;
50
+ /**
51
+ * Check connection status.
52
+ *
53
+ * @returns Whether this instance is connected to a PostgreSQL database.
54
+ */
27
55
  isConnected(): boolean;
56
+ private createEntitiesTable;
57
+ private addTilmeldColumnsAndIndexes;
58
+ private createEntitiesTilmeldIndexes;
59
+ private createDataTable;
60
+ private createReferencesTable;
61
+ private createTokensTable;
62
+ private createUniquesTable;
63
+ /**
64
+ * Create entity tables in the database.
65
+ *
66
+ * @param etype The entity type to create a table for. If this is blank, the default tables are created.
67
+ * @returns True on success, false on failure.
68
+ */
28
69
  private createTables;
29
70
  private translateQuery;
30
71
  private query;
31
- private querySync;
72
+ private queryArray;
32
73
  private queryIter;
33
- private queryIterSync;
34
74
  private queryGet;
35
75
  private queryRun;
36
- private queryRunSync;
37
76
  commit(name: string): Promise<boolean>;
38
77
  deleteEntityByID(guid: string, className?: EntityConstructor | string | null): Promise<boolean>;
39
78
  deleteUID(name: string): Promise<boolean>;
40
- protected exportEntities(writeLine: (line: string) => void): Promise<void>;
79
+ getIndexes(etype: string): Promise<{
80
+ scope: 'data' | 'references' | 'tokens';
81
+ name: string;
82
+ property: string;
83
+ }[]>;
84
+ addIndex(etype: string, definition: {
85
+ scope: 'data' | 'references' | 'tokens';
86
+ name: string;
87
+ property: string;
88
+ }): Promise<boolean>;
89
+ deleteIndex(etype: string, scope: 'data' | 'references' | 'tokens', name: string): Promise<boolean>;
90
+ getEtypes(): Promise<string[]>;
91
+ exportDataIterator(): AsyncGenerator<{
92
+ type: 'comment' | 'uid' | 'entity';
93
+ content: string;
94
+ }, void, false | undefined>;
95
+ /**
96
+ * Generate the PostgreSQL query.
97
+ * @param options The options array.
98
+ * @param formattedSelectors The formatted selector array.
99
+ * @param etype
100
+ * @param count Used to track internal params.
101
+ * @param params Used to store internal params.
102
+ * @param subquery Whether only a subquery should be returned.
103
+ * @returns The SQL query.
104
+ */
41
105
  private makeEntityQuery;
42
106
  protected performQuery(options: Options, formattedSelectors: FormattedSelector[], etype: string): {
43
107
  result: any;
44
108
  };
45
- protected performQuerySync(options: Options, formattedSelectors: FormattedSelector[], etype: string): {
46
- result: any;
47
- };
48
109
  getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
49
110
  return: 'count';
50
111
  }, ...selectors: Selector[]): Promise<number>;
51
112
  getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
52
113
  return: 'guid';
53
114
  }, ...selectors: Selector[]): Promise<string[]>;
54
- getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<ReturnType<T['factorySync']>[]>;
55
- protected getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
56
- return: 'count';
57
- }, ...selectors: Selector[]): number;
58
- protected getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
59
- return: 'guid';
60
- }, ...selectors: Selector[]): string[];
61
- protected getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): ReturnType<T['factorySync']>[];
115
+ getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
116
+ return: 'object';
117
+ }, ...selectors: Selector[]): Promise<EntityObjectType<T>[]>;
118
+ getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T>[]>;
62
119
  getUID(name: string): Promise<number | null>;
63
- import(filename: string): Promise<boolean>;
120
+ importEntity(entity: {
121
+ guid: string;
122
+ cdate: number;
123
+ mdate: number;
124
+ tags: string[];
125
+ sdata: SerializedEntityData;
126
+ etype: string;
127
+ }): Promise<void>;
128
+ importEntityTokens(entity: {
129
+ guid: string;
130
+ cdate: number;
131
+ mdate: number;
132
+ tags: string[];
133
+ sdata: SerializedEntityData;
134
+ etype: string;
135
+ }): Promise<void>;
136
+ importEntityTilmeldAC(entity: {
137
+ guid: string;
138
+ cdate: number;
139
+ mdate: number;
140
+ tags: string[];
141
+ sdata: SerializedEntityData;
142
+ etype: string;
143
+ }): Promise<void>;
144
+ private importEntityInternal;
145
+ importUID({ name, value }: {
146
+ name: string;
147
+ value: number;
148
+ }): Promise<void>;
64
149
  newUID(name: string): Promise<number>;
65
150
  renameUID(oldName: string, newName: string): Promise<boolean>;
66
151
  rollback(name: string): Promise<boolean>;
67
152
  saveEntity(entity: EntityInterface): Promise<boolean>;
68
153
  setUID(name: string, curUid: number): Promise<boolean>;
69
- private internalTransaction;
154
+ protected internalTransaction(name: string, setOnSelf?: boolean): Promise<PostgreSQLDriverTransaction>;
70
155
  startTransaction(name: string): Promise<import("@nymphjs/nymph").Nymph>;
156
+ private removeTilmeldOldRows;
157
+ needsMigration(): Promise<'json' | 'tokens' | 'tilmeldColumns' | false>;
158
+ liveMigration(migrationType: 'tokenTables' | 'tilmeldColumns' | 'tilmeldRemoveOldRows'): Promise<void>;
71
159
  }
72
160
  export {};