@nocobase/database 1.8.0-beta.7 → 1.8.0-beta.9
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.
|
@@ -64,8 +64,10 @@ const _BelongsToArrayAssociation = class _BelongsToArrayAssociation {
|
|
|
64
64
|
targetKey;
|
|
65
65
|
identifierField;
|
|
66
66
|
as;
|
|
67
|
+
options;
|
|
67
68
|
constructor(options) {
|
|
68
69
|
const { db, source, as, foreignKey, target, targetKey } = options;
|
|
70
|
+
this.options = options;
|
|
69
71
|
this.associationType = "BelongsToArray";
|
|
70
72
|
this.db = db;
|
|
71
73
|
this.source = source;
|
package/lib/repository.d.ts
CHANGED
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/// <reference types="node" />
|
|
10
10
|
import { Association, BulkCreateOptions, ModelStatic, FindAndCountOptions as SequelizeAndCountOptions, CountOptions as SequelizeCountOptions, CreateOptions as SequelizeCreateOptions, DestroyOptions as SequelizeDestroyOptions, FindOptions as SequelizeFindOptions, UpdateOptions as SequelizeUpdateOptions, Transactionable, WhereOperators } from 'sequelize';
|
|
11
|
+
import { BelongsToArrayRepository } from './belongs-to-array/belongs-to-array-repository';
|
|
11
12
|
import { Collection } from './collection';
|
|
13
|
+
import { SmartCursorBuilder } from './cursor-builder';
|
|
12
14
|
import { Database } from './database';
|
|
13
15
|
import { ArrayFieldRepository } from './field-repository/array-field-repository';
|
|
14
16
|
import { Model } from './model';
|
|
15
17
|
import operators from './operators';
|
|
16
|
-
import { BelongsToArrayRepository } from './belongs-to-array/belongs-to-array-repository';
|
|
17
18
|
import { BelongsToManyRepository } from './relation-repository/belongs-to-many-repository';
|
|
18
19
|
import { BelongsToRepository } from './relation-repository/belongs-to-repository';
|
|
19
20
|
import { HasManyRepository } from './relation-repository/hasmany-repository';
|
|
20
21
|
import { HasOneRepository } from './relation-repository/hasone-repository';
|
|
21
22
|
import { RelationRepository } from './relation-repository/relation-repository';
|
|
22
23
|
import { valuesToFilter } from './utils/filter-utils';
|
|
23
|
-
import { SmartCursorBuilder } from './cursor-builder';
|
|
24
24
|
interface CreateManyOptions extends BulkCreateOptions {
|
|
25
25
|
records: Values[];
|
|
26
26
|
}
|
|
@@ -141,6 +141,7 @@ export interface FirstOrCreateOptions extends Transactionable {
|
|
|
141
141
|
values?: Values;
|
|
142
142
|
hooks?: boolean;
|
|
143
143
|
context?: any;
|
|
144
|
+
updateAssociationValues?: AssociationKeysToBeUpdate;
|
|
144
145
|
}
|
|
145
146
|
export declare class Repository<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes> {
|
|
146
147
|
database: Database;
|
package/lib/repository.js
CHANGED
|
@@ -54,6 +54,9 @@ module.exports = __toCommonJS(repository_exports);
|
|
|
54
54
|
var import_utils = require("@nocobase/utils");
|
|
55
55
|
var import_lodash = __toESM(require("lodash"));
|
|
56
56
|
var import_sequelize = require("sequelize");
|
|
57
|
+
var import_lodash2 = __toESM(require("lodash"));
|
|
58
|
+
var import_belongs_to_array_repository = require("./belongs-to-array/belongs-to-array-repository");
|
|
59
|
+
var import_cursor_builder = require("./cursor-builder");
|
|
57
60
|
var import_must_have_filter_decorator = __toESM(require("./decorators/must-have-filter-decorator"));
|
|
58
61
|
var import_target_collection_decorator = __toESM(require("./decorators/target-collection-decorator"));
|
|
59
62
|
var import_transaction_decorator = require("./decorators/transaction-decorator");
|
|
@@ -62,7 +65,6 @@ var import_array_field_repository = require("./field-repository/array-field-repo
|
|
|
62
65
|
var import_fields = require("./fields");
|
|
63
66
|
var import_filter_parser = __toESM(require("./filter-parser"));
|
|
64
67
|
var import_options_parser = require("./options-parser");
|
|
65
|
-
var import_belongs_to_array_repository = require("./belongs-to-array/belongs-to-array-repository");
|
|
66
68
|
var import_belongs_to_many_repository = require("./relation-repository/belongs-to-many-repository");
|
|
67
69
|
var import_belongs_to_repository = require("./relation-repository/belongs-to-repository");
|
|
68
70
|
var import_hasmany_repository = require("./relation-repository/hasmany-repository");
|
|
@@ -70,8 +72,6 @@ var import_hasone_repository = require("./relation-repository/hasone-repository"
|
|
|
70
72
|
var import_update_associations = require("./update-associations");
|
|
71
73
|
var import_update_guard = require("./update-guard");
|
|
72
74
|
var import_filter_utils = require("./utils/filter-utils");
|
|
73
|
-
var import_lodash2 = __toESM(require("lodash"));
|
|
74
|
-
var import_cursor_builder = require("./cursor-builder");
|
|
75
75
|
var import_sequelize2 = require("sequelize");
|
|
76
76
|
const debug = require("debug")("noco-database");
|
|
77
77
|
const transaction = (0, import_transaction_decorator.transactionWrapperBuilder)(function() {
|
|
@@ -333,16 +333,16 @@ const _Repository = class _Repository {
|
|
|
333
333
|
* Get the first record matching the attributes or create it.
|
|
334
334
|
*/
|
|
335
335
|
async firstOrCreate(options) {
|
|
336
|
-
const { filterKeys, values, transaction: transaction2,
|
|
336
|
+
const { filterKeys, values, transaction: transaction2, context, ...rest } = options;
|
|
337
337
|
const filter = _Repository.valuesToFilter(values, filterKeys);
|
|
338
338
|
const instance = await this.findOne({ filter, transaction: transaction2, context });
|
|
339
339
|
if (instance) {
|
|
340
340
|
return instance;
|
|
341
341
|
}
|
|
342
|
-
return this.create({ values, transaction: transaction2,
|
|
342
|
+
return this.create({ values, transaction: transaction2, context, ...rest });
|
|
343
343
|
}
|
|
344
344
|
async updateOrCreate(options) {
|
|
345
|
-
const { filterKeys, values, transaction: transaction2,
|
|
345
|
+
const { filterKeys, values, transaction: transaction2, context, ...rest } = options;
|
|
346
346
|
const filter = _Repository.valuesToFilter(values, filterKeys);
|
|
347
347
|
const instance = await this.findOne({ filter, transaction: transaction2, context });
|
|
348
348
|
if (instance) {
|
|
@@ -350,11 +350,11 @@ const _Repository = class _Repository {
|
|
|
350
350
|
filterByTk: instance.get(this.collection.filterTargetKey || this.collection.model.primaryKeyAttribute),
|
|
351
351
|
values,
|
|
352
352
|
transaction: transaction2,
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
context,
|
|
354
|
+
...rest
|
|
355
355
|
});
|
|
356
356
|
}
|
|
357
|
-
return this.create({ values, transaction: transaction2,
|
|
357
|
+
return this.create({ values, transaction: transaction2, context, ...rest });
|
|
358
358
|
}
|
|
359
359
|
async create(options) {
|
|
360
360
|
if (Array.isArray(options.values)) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.8.0-beta.
|
|
3
|
+
"version": "1.8.0-beta.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "AGPL-3.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "1.8.0-beta.
|
|
10
|
-
"@nocobase/utils": "1.8.0-beta.
|
|
9
|
+
"@nocobase/logger": "1.8.0-beta.9",
|
|
10
|
+
"@nocobase/utils": "1.8.0-beta.9",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
39
39
|
"directory": "packages/database"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "a3449d646c72965845f8c52e52fff9dba759c564"
|
|
42
42
|
}
|