@l-v-yonsama/multi-platform-database-drivers 0.1.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/.editorconfig +15 -0
- package/.eslintignore +1 -0
- package/.eslintrc.json +30 -0
- package/.github/workflows/npm-publish-github-packages.yml +50 -0
- package/.prettierrc +12 -0
- package/README.md +7 -0
- package/__tests__/db/drivers/AwsS3Driver.test.ts +97 -0
- package/__tests__/db/drivers/MySQLDriver.test.ts +140 -0
- package/__tests__/db/drivers/PostgresDriver.test.ts +139 -0
- package/__tests__/db/drivers/RedisDriver.test.ts +156 -0
- package/jest.config.js +18 -0
- package/package.json +76 -0
- package/src/db/DBError.ts +26 -0
- package/src/db/drivers/AwsS3Driver.ts +539 -0
- package/src/db/drivers/BaseDriver.ts +256 -0
- package/src/db/drivers/MongoDriver.js +110 -0
- package/src/db/drivers/MySQLDriver.ts +318 -0
- package/src/db/drivers/PostgresDriver.ts +363 -0
- package/src/db/drivers/RedisDriver.ts +277 -0
- package/src/db/manager.ts +95 -0
- package/src/db/resource/DbResource.ts +579 -0
- package/src/db/resource/MultipleResultSetDataHolder.ts +119 -0
- package/src/db/resource/ResourceUtil.ts +366 -0
- package/src/db/resource/ResultSetDataHolder.ts +806 -0
- package/src/db/resource/types/DBType.ts +43 -0
- package/src/db/resource/types/GeneralColumnType.ts +321 -0
- package/src/db/resource/types/MySQLColumnType.ts +134 -0
- package/src/db/resource/types/ODBCVendorType.ts +3 -0
- package/src/db/resource/types/PostgresColumnType.ts +94 -0
- package/src/db/resource/types/RedisKeyType.ts +48 -0
- package/src/db/resource/types/ResourceType.ts +10 -0
- package/src/main.ts +1 -0
- package/src/service/request/general_db_request.ts +20 -0
- package/src/service/request/redis_request.ts +21 -0
- package/src/service/request/s3_request.ts +15 -0
- package/src/service/response/GeneralReponse.ts +10 -0
- package/src/types/DateModifiedType.ts +75 -0
- package/src/types/FileKindType.ts +80 -0
- package/src/util/file_util.ts +178 -0
- package/tsconfig.json +23 -0
- package/tsconfig.release.json +23 -0
- package/unit-test.yml +41 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// import MongoDriver from './drivers/MongoDriver'
|
|
2
|
+
// import ODBCDriver from './drivers/ODBCDriver';
|
|
3
|
+
import RedisDriver from './drivers/RedisDriver';
|
|
4
|
+
import MySQLDriver from './drivers/MySQLDriver';
|
|
5
|
+
import PostgresDriver from './drivers/PostgresDriver';
|
|
6
|
+
import AwsS3Driver from './drivers/AwsS3Driver';
|
|
7
|
+
// import FirestoreDriver from "./drivers/FirestoreDriver";
|
|
8
|
+
import BaseDriver from './drivers/BaseDriver';
|
|
9
|
+
import { DbConnection, DbResource } from './resource/DbResource';
|
|
10
|
+
import { DBType } from './resource/types/DBType';
|
|
11
|
+
|
|
12
|
+
const driverMap = new Map<string, BaseDriver>();
|
|
13
|
+
const conResList = new Array<DbConnection>();
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
getConResList,
|
|
17
|
+
getDefByName,
|
|
18
|
+
getDefById,
|
|
19
|
+
getDriverById,
|
|
20
|
+
asyncCloseAll,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function getConResList(): Array<DbConnection> {
|
|
24
|
+
return conResList;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getDefById(id: string): DbConnection | undefined {
|
|
28
|
+
return conResList.find((def) => def.id === id);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getDefByName(defName: string): DbConnection | undefined {
|
|
32
|
+
return conResList.find((def) => def.name === defName);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getDriverById(id: string): BaseDriver | undefined {
|
|
36
|
+
const conDef = getDefById(id);
|
|
37
|
+
if (conDef === undefined) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
let driver = driverMap.get(id);
|
|
41
|
+
if (driver) {
|
|
42
|
+
return driver;
|
|
43
|
+
}
|
|
44
|
+
driver = createDriver(conDef);
|
|
45
|
+
if (driver) {
|
|
46
|
+
driverMap.set(id, driver);
|
|
47
|
+
}
|
|
48
|
+
return driver;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createDriver(conRes: DbConnection): BaseDriver | undefined {
|
|
52
|
+
let driver = undefined;
|
|
53
|
+
switch (conRes.db_type) {
|
|
54
|
+
// case DBType.ODBC:
|
|
55
|
+
// driver = new ODBCDriver(conRes);
|
|
56
|
+
// break;
|
|
57
|
+
case DBType.MySQL:
|
|
58
|
+
driver = new MySQLDriver(conRes);
|
|
59
|
+
break;
|
|
60
|
+
case DBType.Postgres:
|
|
61
|
+
driver = new PostgresDriver(conRes);
|
|
62
|
+
break;
|
|
63
|
+
case DBType.Redis:
|
|
64
|
+
driver = new RedisDriver(conRes);
|
|
65
|
+
break;
|
|
66
|
+
// case DBType.Firestore:
|
|
67
|
+
// // driver = new FirestoreDriver(conRes);
|
|
68
|
+
// break;
|
|
69
|
+
case DBType.AwsS3:
|
|
70
|
+
case DBType.Minio:
|
|
71
|
+
driver = new AwsS3Driver(conRes);
|
|
72
|
+
break;
|
|
73
|
+
// case DBType.Mongodb:
|
|
74
|
+
// // driver = new MongoDriver(conDef)
|
|
75
|
+
// break
|
|
76
|
+
// case DBType.IndexedDB:
|
|
77
|
+
// driver = new IndexedDBDriver(conRes);
|
|
78
|
+
// break;
|
|
79
|
+
default:
|
|
80
|
+
throw new Error(`${conRes.db_type} is not supported.`);
|
|
81
|
+
}
|
|
82
|
+
return driver;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function asyncCloseAll(): Promise<string> {
|
|
86
|
+
let errorMessage = '';
|
|
87
|
+
driverMap.forEach(async (driver: BaseDriver) => {
|
|
88
|
+
try {
|
|
89
|
+
await driver.asyncClose();
|
|
90
|
+
} catch (e) {
|
|
91
|
+
errorMessage += e.message + '\n';
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return errorMessage;
|
|
95
|
+
}
|
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
import { GeneralColumnType } from './types/GeneralColumnType';
|
|
2
|
+
import { ResourceType } from './types/ResourceType';
|
|
3
|
+
import { DBType } from './types/DBType';
|
|
4
|
+
import { RedisKeyType } from './types/RedisKeyType';
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
import ShortUniqueId from 'short-unique-id';
|
|
7
|
+
import { ODBCVendorType } from './types/ODBCVendorType';
|
|
8
|
+
|
|
9
|
+
const uid = new ShortUniqueId();
|
|
10
|
+
|
|
11
|
+
const unwrapQuote = (n: string): string => {
|
|
12
|
+
if (n && n.startsWith('"') && n.endsWith('"')) {
|
|
13
|
+
return n.substring(1, n.length - 1);
|
|
14
|
+
}
|
|
15
|
+
return n;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface Proposal {
|
|
19
|
+
s?: string;
|
|
20
|
+
t?: string;
|
|
21
|
+
name: string;
|
|
22
|
+
comment?: string;
|
|
23
|
+
type: ResourceType;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SchemaAndTableName {
|
|
27
|
+
schema?: string;
|
|
28
|
+
table: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TableRows extends SchemaAndTableName {
|
|
32
|
+
count: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SchemaAndTableHints {
|
|
36
|
+
list: SchemaAndTableName[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ColumnResolver {
|
|
40
|
+
hints: SchemaAndTableHints;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class DbResource {
|
|
44
|
+
public id = uid.randomUUID(8);
|
|
45
|
+
protected parent: DbResource | undefined;
|
|
46
|
+
protected resouce_type: ResourceType;
|
|
47
|
+
public name: string;
|
|
48
|
+
public comment?: string;
|
|
49
|
+
protected children: Array<DbResource>;
|
|
50
|
+
public expanded = false;
|
|
51
|
+
|
|
52
|
+
public static createEmpty(): DbResource {
|
|
53
|
+
const r = new DbResource(ResourceType.Database, '');
|
|
54
|
+
return r;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
constructor(resouce_type: ResourceType, name: string) {
|
|
58
|
+
this.resouce_type = resouce_type;
|
|
59
|
+
this.name = name;
|
|
60
|
+
this.children = [];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getName(): string {
|
|
64
|
+
return this.name;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getResouceType(): ResourceType {
|
|
68
|
+
return this.resouce_type;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getChildren(): DbResource[] {
|
|
72
|
+
return this.children;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getParent(): DbResource | undefined {
|
|
76
|
+
return this.parent;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
addChild(res: DbResource): DbResource {
|
|
80
|
+
this.children.push(res);
|
|
81
|
+
res.parent = this;
|
|
82
|
+
return res;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
containsResource(filter: string): boolean {
|
|
86
|
+
if (!filter) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
if (this.name.toUpperCase().indexOf(filter) >= 0) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (
|
|
93
|
+
this.comment &&
|
|
94
|
+
('' || this.comment).toUpperCase().indexOf(filter) >= 0
|
|
95
|
+
) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
for (const child of this.children) {
|
|
99
|
+
if (child.containsResource(filter)) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
clearChildren(): void {
|
|
107
|
+
this.children.splice(0, this.children.length);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getChildByName(name: string, options?: any): DbResource | undefined {
|
|
111
|
+
name = name.toUpperCase();
|
|
112
|
+
if (options && options.quote_ident === true) {
|
|
113
|
+
name = unwrapQuote(name);
|
|
114
|
+
return this.children.find(
|
|
115
|
+
(a) => unwrapQuote(a.getName()).toUpperCase() === name,
|
|
116
|
+
);
|
|
117
|
+
} else {
|
|
118
|
+
return this.children.find((a) => a.getName().toUpperCase() === name);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
toString(): string {
|
|
122
|
+
return `[${this.resouce_type}]:${this.name}`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface SshSetting {
|
|
127
|
+
use: boolean;
|
|
128
|
+
auth_method: string;
|
|
129
|
+
username: string;
|
|
130
|
+
password?: string;
|
|
131
|
+
host: string;
|
|
132
|
+
port: number;
|
|
133
|
+
privateKeyPath?: string;
|
|
134
|
+
privateKey?: string;
|
|
135
|
+
passphrase?: string;
|
|
136
|
+
dstPort: number;
|
|
137
|
+
dstHost: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface FirebaseSetting {
|
|
141
|
+
auth_method: string;
|
|
142
|
+
projectid?: string;
|
|
143
|
+
private_key?: string;
|
|
144
|
+
client_email?: string;
|
|
145
|
+
serviceAccountCredentialsPath?: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface ConnectionSetting {
|
|
149
|
+
db_type: DBType;
|
|
150
|
+
odbc_vendor_type?: ODBCVendorType;
|
|
151
|
+
name?: string;
|
|
152
|
+
url?: string;
|
|
153
|
+
host?: string;
|
|
154
|
+
port?: number;
|
|
155
|
+
enviroment?: string;
|
|
156
|
+
user?: string;
|
|
157
|
+
password?: string;
|
|
158
|
+
database?: string;
|
|
159
|
+
database_version?: number;
|
|
160
|
+
ds?: string;
|
|
161
|
+
region?: string;
|
|
162
|
+
isConnected?: boolean;
|
|
163
|
+
is_in_progress?: boolean;
|
|
164
|
+
apiVersion?: string;
|
|
165
|
+
ssh?: SshSetting;
|
|
166
|
+
firebase?: FirebaseSetting;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export class DbConnection extends DbResource implements ConnectionSetting {
|
|
170
|
+
public property: Map<string, object>;
|
|
171
|
+
public db_type = DBType.Unknown;
|
|
172
|
+
public odbc_vendor_type = ODBCVendorType.Oracle;
|
|
173
|
+
public host = '';
|
|
174
|
+
public port = 0;
|
|
175
|
+
public user = '';
|
|
176
|
+
public password = '';
|
|
177
|
+
public database = '';
|
|
178
|
+
public database_version = 1;
|
|
179
|
+
public enviroment = '';
|
|
180
|
+
public ds = '';
|
|
181
|
+
public url = '';
|
|
182
|
+
public isConnected = false;
|
|
183
|
+
public is_in_progress = false;
|
|
184
|
+
public apiVersion?: string;
|
|
185
|
+
public region?: string;
|
|
186
|
+
public ssh?: SshSetting;
|
|
187
|
+
public firebase?: FirebaseSetting;
|
|
188
|
+
|
|
189
|
+
constructor(prop: any) {
|
|
190
|
+
super(ResourceType.Connection, prop.name);
|
|
191
|
+
this.id = prop.id;
|
|
192
|
+
this.db_type = DBType.parse(prop['db_type']);
|
|
193
|
+
this.odbc_vendor_type = prop.odbc_vendor_type;
|
|
194
|
+
this.property = new Map<string, object>();
|
|
195
|
+
this.host = prop.host;
|
|
196
|
+
this.port = prop.port;
|
|
197
|
+
this.user = prop.user;
|
|
198
|
+
this.password = prop.password;
|
|
199
|
+
this.enviroment = prop.enviroment;
|
|
200
|
+
this.database = prop.database;
|
|
201
|
+
this.database_version = prop.database_version;
|
|
202
|
+
this.ds = prop.ds;
|
|
203
|
+
this.url = prop.url;
|
|
204
|
+
this.apiVersion = prop.apiVersion;
|
|
205
|
+
this.region = prop.region;
|
|
206
|
+
this.ssh = prop.ssh;
|
|
207
|
+
this.firebase = prop.firebase;
|
|
208
|
+
if (prop.property) {
|
|
209
|
+
for (const k in prop.property) {
|
|
210
|
+
this.property.set(k, prop.property[k]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
isInProgress(): boolean {
|
|
216
|
+
return this.is_in_progress;
|
|
217
|
+
}
|
|
218
|
+
static deserialize(json: any): DbConnection {
|
|
219
|
+
const con = new DbConnection(json);
|
|
220
|
+
if (json.children && json.children.length > 0) {
|
|
221
|
+
json.children.forEach((childJson: any) => {
|
|
222
|
+
if (con.db_type === DBType.Redis) {
|
|
223
|
+
con.addChild(RedisDatabase.deserialize(con, childJson));
|
|
224
|
+
} else {
|
|
225
|
+
con.addChild(DbDatabase.deserialize(con, childJson));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
con.isConnected = json.isConnected;
|
|
230
|
+
return con;
|
|
231
|
+
}
|
|
232
|
+
public hasUrl(): boolean {
|
|
233
|
+
if (this.url && this.url.length > 0) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
public hasSshSetting(): boolean {
|
|
239
|
+
if (this.ssh && this.ssh.use === true) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export class DbDatabase extends DbResource {
|
|
247
|
+
public disabled = false;
|
|
248
|
+
version?: number;
|
|
249
|
+
constructor(name: string) {
|
|
250
|
+
super(ResourceType.Database, name);
|
|
251
|
+
}
|
|
252
|
+
static deserialize(con: DbConnection, json: any): DbDatabase {
|
|
253
|
+
const own = new DbDatabase(json.name);
|
|
254
|
+
if (json.comment) {
|
|
255
|
+
own.comment = json.comment;
|
|
256
|
+
}
|
|
257
|
+
if (json.version) {
|
|
258
|
+
own.version = json.version;
|
|
259
|
+
}
|
|
260
|
+
if (json.disabled) {
|
|
261
|
+
own.disabled = json.disabled;
|
|
262
|
+
}
|
|
263
|
+
if (json.children && json.children.length > 0) {
|
|
264
|
+
json.children.forEach((childJson: any) => {
|
|
265
|
+
// console.log('childJson=', childJson)
|
|
266
|
+
switch (childJson.resouce_type) {
|
|
267
|
+
case ResourceType.Schema:
|
|
268
|
+
own.addChild(DbSchema.deserialize(con, own, childJson));
|
|
269
|
+
break;
|
|
270
|
+
case ResourceType.Bucket:
|
|
271
|
+
own.addChild(DbS3Bucket.deserialize(con, own, childJson));
|
|
272
|
+
break;
|
|
273
|
+
case ResourceType.Owner:
|
|
274
|
+
own.addChild(DbS3Owner.deserialize(con, own, childJson));
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
throw new Error(
|
|
278
|
+
`DbDatabase#deserialize Undefined resource type:${childJson.resouce_type}`,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
return own;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export class RedisDatabase extends DbDatabase {
|
|
288
|
+
public keys: number;
|
|
289
|
+
public expires: number;
|
|
290
|
+
public avg_ttl: number;
|
|
291
|
+
|
|
292
|
+
constructor(name: string, keys: number, expires: number, avg_ttl: number) {
|
|
293
|
+
super(name);
|
|
294
|
+
this.keys = keys;
|
|
295
|
+
this.expires = expires;
|
|
296
|
+
this.avg_ttl = avg_ttl;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
public getDBIndex(): number {
|
|
300
|
+
return parseInt(this.name, 10);
|
|
301
|
+
}
|
|
302
|
+
static deserialize(con: DbConnection, json: any): RedisDatabase {
|
|
303
|
+
const own = new RedisDatabase(
|
|
304
|
+
json.name,
|
|
305
|
+
json.keys,
|
|
306
|
+
json.expires,
|
|
307
|
+
json.avg_ttl,
|
|
308
|
+
);
|
|
309
|
+
if (json.children && json.children.length > 0) {
|
|
310
|
+
json.children.forEach((childJson: any) => {
|
|
311
|
+
own.addChild(DbKey.deserialize(childJson));
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return own;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export class DbSchema extends DbResource {
|
|
319
|
+
constructor(name: string) {
|
|
320
|
+
super(ResourceType.Schema, name);
|
|
321
|
+
}
|
|
322
|
+
static deserialize(con: DbConnection, db: DbDatabase, json: any): DbSchema {
|
|
323
|
+
const own = new DbSchema(json.name);
|
|
324
|
+
if (json.children && json.children.length > 0) {
|
|
325
|
+
json.children.forEach((childJson: any) => {
|
|
326
|
+
own.addChild(DbTable.deserialize(con, db, own, childJson));
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
return own;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export class DbTable extends DbResource {
|
|
334
|
+
public table_type: any;
|
|
335
|
+
public is_in_progress = false;
|
|
336
|
+
constructor(name: string, table_type: any, comment = '') {
|
|
337
|
+
super(ResourceType.Table, name);
|
|
338
|
+
this.table_type = table_type;
|
|
339
|
+
this.comment = comment || '';
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
toString(): string {
|
|
343
|
+
return `[${super.toString()}]: Type[${this.table_type}]`;
|
|
344
|
+
}
|
|
345
|
+
static deserialize(
|
|
346
|
+
con: DbConnection,
|
|
347
|
+
db: DbDatabase,
|
|
348
|
+
schema: DbSchema,
|
|
349
|
+
json: any,
|
|
350
|
+
): DbTable {
|
|
351
|
+
const own = new DbTable(json.name, json.table_type, json.comment);
|
|
352
|
+
if (json.children && json.children.length > 0) {
|
|
353
|
+
json.children.forEach((childJson: any) => {
|
|
354
|
+
own.addChild(DbColumn.deserialize(con, db, schema, own, childJson));
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return own;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export class DbKey extends DbResource {
|
|
362
|
+
public type = RedisKeyType.UNKNOWN;
|
|
363
|
+
public ttl = -1;
|
|
364
|
+
public ttl_confirmation_datetime: number | undefined;
|
|
365
|
+
public ttl_remain: number | undefined;
|
|
366
|
+
public val: any;
|
|
367
|
+
|
|
368
|
+
constructor(name: string, type = RedisKeyType.UNKNOWN, ttl = -1) {
|
|
369
|
+
super(ResourceType.Key, name);
|
|
370
|
+
this.type = type;
|
|
371
|
+
this.ttl = ttl;
|
|
372
|
+
if (ttl > 0) {
|
|
373
|
+
this.ttl_remain = this.ttl;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
toString(): string {
|
|
377
|
+
if (this.ttl < 0) {
|
|
378
|
+
return `${super.toString()} TYPE[${this.type}]`;
|
|
379
|
+
}
|
|
380
|
+
return `${super.toString()} TYPE[${this.type}] TTL[${this.ttl}]`;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
static deserialize(json: any): DbKey {
|
|
384
|
+
const own = new DbKey(json.name, json.type, json.ttl);
|
|
385
|
+
own.ttl_confirmation_datetime = json.ttl_confirmation_datetime;
|
|
386
|
+
if (own.ttl > 0 && own.ttl_confirmation_datetime) {
|
|
387
|
+
const sub = Math.round(
|
|
388
|
+
(Date.now() - own.ttl_confirmation_datetime) / 1000,
|
|
389
|
+
);
|
|
390
|
+
const r = own.ttl - sub;
|
|
391
|
+
if (r > 0) {
|
|
392
|
+
own.ttl_remain = own.ttl;
|
|
393
|
+
} else {
|
|
394
|
+
own.ttl_remain = undefined;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
own.val = json.val;
|
|
398
|
+
return own;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export class DbColumn extends DbResource {
|
|
403
|
+
public readonly col_type: GeneralColumnType;
|
|
404
|
+
public readonly nullable: boolean;
|
|
405
|
+
public readonly key: string | undefined;
|
|
406
|
+
public readonly default: any;
|
|
407
|
+
public readonly extra: any;
|
|
408
|
+
constructor(
|
|
409
|
+
name: string,
|
|
410
|
+
col_type = GeneralColumnType.UNKNOWN,
|
|
411
|
+
params: any,
|
|
412
|
+
comment = '',
|
|
413
|
+
) {
|
|
414
|
+
super(ResourceType.Column, name);
|
|
415
|
+
if (comment === null) {
|
|
416
|
+
comment = '';
|
|
417
|
+
}
|
|
418
|
+
this.col_type = col_type;
|
|
419
|
+
if (typeof comment !== 'string') {
|
|
420
|
+
console.trace('error comment type', typeof comment, ' comment=', comment);
|
|
421
|
+
}
|
|
422
|
+
this.comment = comment || '';
|
|
423
|
+
if (params) {
|
|
424
|
+
this.nullable = params.nullable || false;
|
|
425
|
+
this.key = params.key || '';
|
|
426
|
+
this.default = params.default;
|
|
427
|
+
this.extra = params.extra;
|
|
428
|
+
} else {
|
|
429
|
+
this.nullable = true;
|
|
430
|
+
this.key = '';
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
static deserialize(
|
|
435
|
+
con: DbConnection,
|
|
436
|
+
db: DbDatabase,
|
|
437
|
+
schema: DbSchema,
|
|
438
|
+
table: DbTable,
|
|
439
|
+
json: any,
|
|
440
|
+
): DbColumn {
|
|
441
|
+
const own = new DbColumn(
|
|
442
|
+
json.name,
|
|
443
|
+
json.col_type,
|
|
444
|
+
json.params,
|
|
445
|
+
json.comment,
|
|
446
|
+
);
|
|
447
|
+
return own;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
getGeneralType(): string {
|
|
451
|
+
// if (
|
|
452
|
+
// this.colType.match(/.*(year|month|yearmonth|date|datetime|timestamp).*/i)
|
|
453
|
+
// ) {
|
|
454
|
+
// return "date";
|
|
455
|
+
// } else if (this.colType.match(/.*(time).*/i)) {
|
|
456
|
+
// return "time";
|
|
457
|
+
// } else if (
|
|
458
|
+
// this.colType.match(/.*(int|float|double|number|numeric|decimal).*/i)
|
|
459
|
+
// ) {
|
|
460
|
+
// return "number";
|
|
461
|
+
// } else if (this.colType.match(/.*(char|string|text).*/i)) {
|
|
462
|
+
// return "string";
|
|
463
|
+
// } else if (this.colType.match(/.*(enum).*/i)) {
|
|
464
|
+
// return "enum";
|
|
465
|
+
// } else if (this.colType.match(/.*(set).*/i)) {
|
|
466
|
+
// return "set";
|
|
467
|
+
// } else {
|
|
468
|
+
// return "undefined";
|
|
469
|
+
// }
|
|
470
|
+
return '' + this.col_type;
|
|
471
|
+
}
|
|
472
|
+
toString(): string {
|
|
473
|
+
return `[${super.toString()}]: GType[${this.getGeneralType()}] Nullable[${
|
|
474
|
+
this.nullable
|
|
475
|
+
}] Key[${this.key}]`;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export class DbS3Bucket extends DbResource {
|
|
480
|
+
public created?: Date;
|
|
481
|
+
public is_in_progress = false;
|
|
482
|
+
public refreshed?: Date;
|
|
483
|
+
|
|
484
|
+
constructor(name?: string, created?: Date) {
|
|
485
|
+
super(ResourceType.Bucket, name === undefined ? '' : name);
|
|
486
|
+
this.created = created;
|
|
487
|
+
}
|
|
488
|
+
public getDir(key: string): DbS3Key | undefined {
|
|
489
|
+
if (key.length === 0) {
|
|
490
|
+
return undefined;
|
|
491
|
+
}
|
|
492
|
+
if (key.endsWith('/')) {
|
|
493
|
+
key = key.substring(0, key.length - 1);
|
|
494
|
+
}
|
|
495
|
+
if (key.startsWith('/')) {
|
|
496
|
+
key = key.substring(1, key.length);
|
|
497
|
+
}
|
|
498
|
+
const dirNames = key.split('/');
|
|
499
|
+
let searchRes = <DbResource>this;
|
|
500
|
+
for (let i = 0; i < dirNames.length; i++) {
|
|
501
|
+
const dir = dirNames[i];
|
|
502
|
+
const r = searchRes.getChildByName(dir + '/');
|
|
503
|
+
if (r === undefined) {
|
|
504
|
+
return undefined;
|
|
505
|
+
}
|
|
506
|
+
searchRes = r;
|
|
507
|
+
}
|
|
508
|
+
return <DbS3Key>searchRes;
|
|
509
|
+
}
|
|
510
|
+
static deserialize(con: DbConnection, db: DbDatabase, json: any): DbS3Bucket {
|
|
511
|
+
const own = new DbS3Bucket(json.name);
|
|
512
|
+
own.created = json.created;
|
|
513
|
+
if (json.refreshed) {
|
|
514
|
+
own.refreshed = dayjs(json.refreshed).toDate();
|
|
515
|
+
}
|
|
516
|
+
if (json.children && json.children.length > 0) {
|
|
517
|
+
json.children.forEach((childJson: any) => {
|
|
518
|
+
own.addChild(DbS3Key.deserialize(childJson));
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
return own;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export class DbS3Owner extends DbResource {
|
|
526
|
+
constructor(id: string, name?: string) {
|
|
527
|
+
super(ResourceType.Owner, name === undefined ? '' : name);
|
|
528
|
+
this.id = id;
|
|
529
|
+
}
|
|
530
|
+
static deserialize(con: DbConnection, db: DbDatabase, json: any): DbS3Owner {
|
|
531
|
+
const own = new DbS3Owner(json.name);
|
|
532
|
+
own.id = json.id;
|
|
533
|
+
return own;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
export interface S3KeySearchResult {
|
|
538
|
+
prefix?: string;
|
|
539
|
+
list: Array<DbS3Key>;
|
|
540
|
+
ContinuationToken: string;
|
|
541
|
+
error_message?: string;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export class DbS3Key extends DbResource {
|
|
545
|
+
public output_file_path?: string;
|
|
546
|
+
public is_dir = false;
|
|
547
|
+
public is_in_progress = false;
|
|
548
|
+
public refreshed?: Date;
|
|
549
|
+
public updated?: Date;
|
|
550
|
+
public etag?: string;
|
|
551
|
+
public size?: number;
|
|
552
|
+
public storage_class?: string;
|
|
553
|
+
public base64?: string;
|
|
554
|
+
|
|
555
|
+
constructor(name: string, is_dir = false) {
|
|
556
|
+
super(ResourceType.Key, name);
|
|
557
|
+
this.is_dir = is_dir;
|
|
558
|
+
}
|
|
559
|
+
toString(): string {
|
|
560
|
+
return `${super.toString()}`;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
static deserialize(json: any): DbS3Key {
|
|
564
|
+
const own = new DbS3Key(json.name);
|
|
565
|
+
own.is_dir = json.is_dir;
|
|
566
|
+
if (json.updated) {
|
|
567
|
+
own.updated = dayjs(json.updated).toDate();
|
|
568
|
+
}
|
|
569
|
+
if (json.refreshed) {
|
|
570
|
+
own.refreshed = dayjs(json.refreshed).toDate();
|
|
571
|
+
}
|
|
572
|
+
own.etag = json.etag;
|
|
573
|
+
own.size = json.size;
|
|
574
|
+
own.storage_class = json.storage_class;
|
|
575
|
+
own.output_file_path = json.output_file_path;
|
|
576
|
+
own.base64 = json.base64;
|
|
577
|
+
return own;
|
|
578
|
+
}
|
|
579
|
+
}
|