@nymphjs/driver-postgresql 1.0.0-beta.13 → 1.0.0-beta.131

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,141 @@ 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
+ exportEntity(etype: string, guid: string): Promise<string>;
96
+ private exportEntityInternal;
97
+ /**
98
+ * Generate the PostgreSQL query.
99
+ * @param options The options array.
100
+ * @param formattedSelectors The formatted selector array.
101
+ * @param etype
102
+ * @param count Used to track internal params.
103
+ * @param params Used to store internal params.
104
+ * @param subquery Whether only a subquery should be returned.
105
+ * @returns The SQL query.
106
+ */
41
107
  private makeEntityQuery;
42
108
  protected performQuery(options: Options, formattedSelectors: FormattedSelector[], etype: string): {
43
109
  result: any;
44
110
  };
45
- protected performQuerySync(options: Options, formattedSelectors: FormattedSelector[], etype: string): {
46
- result: any;
47
- };
48
111
  getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
49
112
  return: 'count';
50
113
  }, ...selectors: Selector[]): Promise<number>;
51
114
  getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
52
115
  return: 'guid';
53
116
  }, ...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']>[];
117
+ getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
118
+ return: 'object';
119
+ }, ...selectors: Selector[]): Promise<EntityObjectType<T>[]>;
120
+ getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T>[]>;
62
121
  getUID(name: string): Promise<number | null>;
63
- import(filename: string): Promise<boolean>;
122
+ importEntity(entity: {
123
+ guid: string;
124
+ cdate: number;
125
+ mdate: number;
126
+ tags: string[];
127
+ sdata: SerializedEntityData;
128
+ etype: string;
129
+ }): Promise<void>;
130
+ importEntityTokens(entity: {
131
+ guid: string;
132
+ cdate: number;
133
+ mdate: number;
134
+ tags: string[];
135
+ sdata: SerializedEntityData;
136
+ etype: string;
137
+ }): Promise<void>;
138
+ importEntityTilmeldAC(entity: {
139
+ guid: string;
140
+ cdate: number;
141
+ mdate: number;
142
+ tags: string[];
143
+ sdata: SerializedEntityData;
144
+ etype: string;
145
+ }): Promise<void>;
146
+ private importEntityInternal;
147
+ importUID({ name, value }: {
148
+ name: string;
149
+ value: number;
150
+ }): Promise<void>;
64
151
  newUID(name: string): Promise<number>;
65
152
  renameUID(oldName: string, newName: string): Promise<boolean>;
66
153
  rollback(name: string): Promise<boolean>;
67
154
  saveEntity(entity: EntityInterface): Promise<boolean>;
68
155
  setUID(name: string, curUid: number): Promise<boolean>;
69
- private internalTransaction;
156
+ protected internalTransaction(name: string, setOnSelf?: boolean): Promise<PostgreSQLDriverTransaction>;
70
157
  startTransaction(name: string): Promise<import("@nymphjs/nymph").Nymph>;
158
+ private removeTilmeldOldRows;
159
+ needsMigration(): Promise<'json' | 'tokens' | 'tilmeldColumns' | false>;
160
+ liveMigration(migrationType: 'tokenTables' | 'tilmeldColumns' | 'tilmeldRemoveOldRows'): Promise<void>;
71
161
  }
72
162
  export {};