vona-module-a-orm 5.0.55 → 5.0.56
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/dist/config/config.d.ts +2 -0
- package/dist/index.js +37 -72
- package/dist/main.d.ts +1 -1
- package/dist/types/model.d.ts +2 -0
- package/package.json +1 -1
package/dist/config/config.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export declare function config(_app: VonaApplication): {
|
|
|
59
59
|
client?: keyof import("vona-module-a-redis").IRedisClientRecord;
|
|
60
60
|
disableInstance?: boolean;
|
|
61
61
|
};
|
|
62
|
+
emptyArrayAsNull?: boolean;
|
|
62
63
|
enable?: boolean;
|
|
63
64
|
meta?: Omit<IOnionOptionsMeta, never> | undefined;
|
|
64
65
|
};
|
|
@@ -81,6 +82,7 @@ export declare function config(_app: VonaApplication): {
|
|
|
81
82
|
client?: keyof import("vona-module-a-redis").IRedisClientRecord;
|
|
82
83
|
disableInstance?: boolean;
|
|
83
84
|
};
|
|
85
|
+
emptyArrayAsNull?: boolean;
|
|
84
86
|
enable?: boolean;
|
|
85
87
|
meta?: Omit<IOnionOptionsMeta, never> | undefined;
|
|
86
88
|
};
|
package/dist/index.js
CHANGED
|
@@ -230,9 +230,16 @@ let ServiceDatabase = (_dec$t = Service(), _dec2$t = BeanInfo({
|
|
|
230
230
|
return !clientName || clientName === 'default' ? this.getDefaultClientName() : clientName;
|
|
231
231
|
}
|
|
232
232
|
getDefaultClientName() {
|
|
233
|
-
|
|
233
|
+
const defaultClient = this.app.config.database.defaultClient;
|
|
234
234
|
if (typeof defaultClient === 'function') {
|
|
235
|
-
|
|
235
|
+
return defaultClient(this.ctx);
|
|
236
|
+
}
|
|
237
|
+
// check instance
|
|
238
|
+
if (!isNil(this.ctx.instanceName)) {
|
|
239
|
+
const configInstanceBase = this.$scope.instance.service.instance.getConfigInstanceBase(this.ctx.instanceName);
|
|
240
|
+
if (configInstanceBase?.isolate) {
|
|
241
|
+
return configInstanceBase.isolateClient;
|
|
242
|
+
}
|
|
236
243
|
}
|
|
237
244
|
return defaultClient;
|
|
238
245
|
}
|
|
@@ -687,10 +694,10 @@ let ServiceDatabaseClient = (_dec$m = Service(), _dec2$m = BeanInfo({
|
|
|
687
694
|
// * should not use this.clientConfig.connection, because password is hidden
|
|
688
695
|
const config = this.getClientConfig(this.clientName, true);
|
|
689
696
|
config.connection = Object.assign({}, config.connection, connDatabaseName);
|
|
690
|
-
// only used by startup, so no consider that
|
|
697
|
+
// only used by startup, so no consider that workers broadcast
|
|
691
698
|
this.configDatabase.clients[this.clientName] = config;
|
|
692
699
|
// reload
|
|
693
|
-
await this.
|
|
700
|
+
await this.scope.service.database.reloadClients(this.clientName, config);
|
|
694
701
|
}
|
|
695
702
|
}) || _class$m) || _class$m);
|
|
696
703
|
|
|
@@ -3095,10 +3102,10 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3095
3102
|
}
|
|
3096
3103
|
// 2: mget
|
|
3097
3104
|
const ids = items.map(item => cast(item).id);
|
|
3098
|
-
const
|
|
3105
|
+
const options3 = params?.columns ? Object.assign({}, options, {
|
|
3099
3106
|
columns: params?.columns
|
|
3100
3107
|
}) : options;
|
|
3101
|
-
return await this.__mget_raw(table, ids,
|
|
3108
|
+
return await this.__mget_raw(table, ids, options3);
|
|
3102
3109
|
}
|
|
3103
3110
|
async __select_cache(table, params, options) {
|
|
3104
3111
|
// check if cache
|
|
@@ -3114,6 +3121,7 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3114
3121
|
// cache
|
|
3115
3122
|
const cache = this.cacheQuery.getInstance(table);
|
|
3116
3123
|
const items = await cache.get(key, {
|
|
3124
|
+
...options?.cache,
|
|
3117
3125
|
get: async () => {
|
|
3118
3126
|
return await super._select(table, params, options, builder);
|
|
3119
3127
|
},
|
|
@@ -3157,9 +3165,12 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3157
3165
|
params.columns = options?.columns;
|
|
3158
3166
|
}
|
|
3159
3167
|
// select
|
|
3160
|
-
const options2 =
|
|
3161
|
-
columns: undefined
|
|
3162
|
-
|
|
3168
|
+
const options2 = deepExtend({}, options, {
|
|
3169
|
+
columns: undefined,
|
|
3170
|
+
cache: {
|
|
3171
|
+
emptyArrayAsNull: true
|
|
3172
|
+
}
|
|
3173
|
+
});
|
|
3163
3174
|
const items = await this.__select_raw(table, params, options2);
|
|
3164
3175
|
return items[0];
|
|
3165
3176
|
}
|
|
@@ -3215,13 +3226,16 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3215
3226
|
const where = !isNil(id) ? Object.assign({}, options?.where, {
|
|
3216
3227
|
id
|
|
3217
3228
|
}) : options?.where;
|
|
3218
|
-
|
|
3219
|
-
where: undefined
|
|
3229
|
+
const options2 = deepExtend({}, options, {
|
|
3230
|
+
where: undefined,
|
|
3231
|
+
cache: {
|
|
3232
|
+
emptyArrayAsNull: true
|
|
3233
|
+
}
|
|
3220
3234
|
});
|
|
3221
3235
|
const items = await this.__select_raw(table, {
|
|
3222
3236
|
where,
|
|
3223
3237
|
columns: ['id']
|
|
3224
|
-
},
|
|
3238
|
+
}, options2);
|
|
3225
3239
|
if (items.length === 0) {
|
|
3226
3240
|
// donothing
|
|
3227
3241
|
return;
|
|
@@ -3273,10 +3287,15 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3273
3287
|
let id = this.__checkCacheKeyValid(where, table);
|
|
3274
3288
|
if (isNil(id)) {
|
|
3275
3289
|
// check where and get id
|
|
3290
|
+
const options2 = deepExtend({}, options, {
|
|
3291
|
+
cache: {
|
|
3292
|
+
emptyArrayAsNull: true
|
|
3293
|
+
}
|
|
3294
|
+
});
|
|
3276
3295
|
const items = await this.__select_raw(table, {
|
|
3277
3296
|
where,
|
|
3278
3297
|
columns: ['id']
|
|
3279
|
-
},
|
|
3298
|
+
}, options2);
|
|
3280
3299
|
if (items.length === 0) {
|
|
3281
3300
|
// donothing
|
|
3282
3301
|
return;
|
|
@@ -3823,71 +3842,17 @@ class Main extends BeanSimple {
|
|
|
3823
3842
|
}
|
|
3824
3843
|
async configLoaded(_config) {}
|
|
3825
3844
|
}
|
|
3826
|
-
async function configDefault(
|
|
3827
|
-
return {
|
|
3828
|
-
testDatabase: false,
|
|
3829
|
-
defaultClient: app.meta.env.DATABASE_DEFAULT_CLIENT,
|
|
3830
|
-
clients: {
|
|
3831
|
-
pg: {
|
|
3832
|
-
client: 'pg',
|
|
3833
|
-
connection: {
|
|
3834
|
-
host: app.meta.env.DATABASE_CLIENT_PG_HOST,
|
|
3835
|
-
port: Number.parseInt(app.meta.env.DATABASE_CLIENT_PG_PORT),
|
|
3836
|
-
user: app.meta.env.DATABASE_CLIENT_PG_USER,
|
|
3837
|
-
password: app.meta.env.DATABASE_CLIENT_PG_PASSWORD,
|
|
3838
|
-
database: app.meta.env.DATABASE_CLIENT_PG_DATABASE
|
|
3839
|
-
}
|
|
3840
|
-
},
|
|
3841
|
-
mysql: {
|
|
3842
|
-
client: 'mysql2',
|
|
3843
|
-
connection: {
|
|
3844
|
-
host: app.meta.env.DATABASE_CLIENT_MYSQL_HOST,
|
|
3845
|
-
port: Number.parseInt(app.meta.env.DATABASE_CLIENT_MYSQL_PORT),
|
|
3846
|
-
user: app.meta.env.DATABASE_CLIENT_MYSQL_USER,
|
|
3847
|
-
password: app.meta.env.DATABASE_CLIENT_MYSQL_PASSWORD,
|
|
3848
|
-
database: app.meta.env.DATABASE_CLIENT_MYSQL_DATABASE
|
|
3849
|
-
}
|
|
3850
|
-
}
|
|
3851
|
-
},
|
|
3852
|
-
base: {
|
|
3853
|
-
pool: {
|
|
3854
|
-
min: 0,
|
|
3855
|
-
max: 5
|
|
3856
|
-
},
|
|
3857
|
-
acquireConnectionTimeout: 60000 * 10,
|
|
3858
|
-
asyncStackTraces: true
|
|
3859
|
-
}
|
|
3860
|
-
};
|
|
3845
|
+
async function configDefault(_app) {
|
|
3846
|
+
return {};
|
|
3861
3847
|
}
|
|
3862
3848
|
async function configDev(_app) {
|
|
3863
|
-
return {
|
|
3864
|
-
testDatabase: true,
|
|
3865
|
-
base: {
|
|
3866
|
-
pool: {
|
|
3867
|
-
min: 0,
|
|
3868
|
-
max: 1
|
|
3869
|
-
}
|
|
3870
|
-
}
|
|
3871
|
-
};
|
|
3849
|
+
return {};
|
|
3872
3850
|
}
|
|
3873
3851
|
async function configProd(_app) {
|
|
3874
|
-
return {
|
|
3875
|
-
testDatabase: false,
|
|
3876
|
-
base: {
|
|
3877
|
-
asyncStackTraces: false
|
|
3878
|
-
}
|
|
3879
|
-
};
|
|
3852
|
+
return {};
|
|
3880
3853
|
}
|
|
3881
3854
|
async function configTest(_app) {
|
|
3882
|
-
return {
|
|
3883
|
-
testDatabase: true,
|
|
3884
|
-
base: {
|
|
3885
|
-
pool: {
|
|
3886
|
-
min: 0,
|
|
3887
|
-
max: 1
|
|
3888
|
-
}
|
|
3889
|
-
}
|
|
3890
|
-
};
|
|
3855
|
+
return {};
|
|
3891
3856
|
}
|
|
3892
3857
|
|
|
3893
3858
|
var _dec, _dec2, _class;
|
package/dist/main.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export declare class Main extends BeanSimple implements IModuleMain {
|
|
|
6
6
|
moduleLoaded(): Promise<void>;
|
|
7
7
|
configLoaded(_config: any): Promise<void>;
|
|
8
8
|
}
|
|
9
|
-
export declare function configDefault(
|
|
9
|
+
export declare function configDefault(_app: VonaApplication): Promise<PowerPartial<ConfigDatabase>>;
|
package/dist/types/model.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
|
+
import type { TSummerCacheActionOptions } from 'vona-module-a-summer';
|
|
2
3
|
import type { BeanModelMeta } from '../bean/bean.model/bean.model_meta.ts';
|
|
3
4
|
import type { TypeModelColumn, TypeModelColumns, TypeModelColumnsPatch, TypeModelWhere } from './modelWhere.ts';
|
|
4
5
|
import type { TypeModelOfModelLike, TypeModelParamsInclude, TypeModelsClassLikeGeneral, TypeSymbolKeyEntity } from './relations.ts';
|
|
@@ -51,6 +52,7 @@ export interface IModelMethodOptionsGeneral {
|
|
|
51
52
|
disableCacheQuery?: boolean;
|
|
52
53
|
disableCacheEntity?: boolean;
|
|
53
54
|
deleted?: boolean;
|
|
55
|
+
cache?: TSummerCacheActionOptions<unknown, unknown>;
|
|
54
56
|
}
|
|
55
57
|
export interface IModelInsertOptionsGeneral<_TRecord, Model extends BeanModelMeta | undefined = undefined> extends IModelMethodOptionsGeneral, IModelMutateRelationIncludeWrapper<Model> {
|
|
56
58
|
}
|