@loopback/sequelize 0.3.0 → 0.5.0
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/README.md +28 -2
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/book-category.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/book.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/category.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/developer.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/doctor-patient.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/doctor.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/index.js +1 -0
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/patient.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/product.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/programming-languange.controller.js +2 -3
- package/dist/.sandbox/40627f10KYa/controllers/task.controller.js +209 -0
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/todo-list-todo.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/todo-list.controller.js +3 -4
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/todo-todo-list.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/todo.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/transaction.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/user-todo-list.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/user.controller.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/datasources/config.js +22 -0
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/datasources/primary.datasource.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/datasources/secondary.datasource.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/appointment.model.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/book.model.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/category.model.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/developer.model.js +9 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/doctor.model.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/index.js +1 -0
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/patient.model.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/product.model.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/programming-language.model.js +9 -3
- package/dist/.sandbox/40627f10KYa/models/task.model.js +73 -0
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/todo-list.model.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/todo.model.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/models/user.model.js +11 -6
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/appointment.repository.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/book.repository.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/category.repository.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/developer.repository.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/doctor.repository.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/index.js +1 -0
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/patient.repository.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/product.repository.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/programming-language.repository.js +2 -3
- package/dist/.sandbox/40627f10KYa/repositories/task.repository.js +25 -0
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/todo-list.repository.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/todo.repository.js +2 -3
- package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/repositories/user.repository.js +2 -3
- package/dist/component.js +2 -3
- package/dist/component.js.map +1 -1
- package/dist/keys.js +1 -1
- package/dist/keys.js.map +1 -1
- package/dist/sequelize/sequelize.datasource.base.d.ts +54 -3
- package/dist/sequelize/sequelize.datasource.base.js +75 -2
- package/dist/sequelize/sequelize.datasource.base.js.map +1 -1
- package/dist/sequelize/sequelize.repository.base.d.ts +70 -3
- package/dist/sequelize/sequelize.repository.base.js +132 -37
- package/dist/sequelize/sequelize.repository.base.js.map +1 -1
- package/package.json +14 -14
- package/src/sequelize/sequelize.datasource.base.ts +121 -4
- package/src/sequelize/sequelize.repository.base.ts +178 -64
- /package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/application.js +0 -0
- /package/dist/.sandbox/{61612HwhooZ → 40627f10KYa}/controllers/test.controller.base.js +0 -0
|
@@ -7,7 +7,7 @@ const repository_1 = require("@loopback/repository");
|
|
|
7
7
|
const sequelize_1 = require("../../../sequelize");
|
|
8
8
|
const primary_datasource_1 = require("../datasources/primary.datasource");
|
|
9
9
|
const index_1 = require("../models/index");
|
|
10
|
-
let TodoListRepository = class TodoListRepository extends sequelize_1.SequelizeCrudRepository {
|
|
10
|
+
let TodoListRepository = exports.TodoListRepository = class TodoListRepository extends sequelize_1.SequelizeCrudRepository {
|
|
11
11
|
constructor(dataSource, todoRepositoryGetter) {
|
|
12
12
|
super(index_1.TodoList, dataSource);
|
|
13
13
|
this.todoRepositoryGetter = todoRepositoryGetter;
|
|
@@ -15,11 +15,10 @@ let TodoListRepository = class TodoListRepository extends sequelize_1.SequelizeC
|
|
|
15
15
|
this.registerInclusionResolver('todos', this.todos.inclusionResolver);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
-
TodoListRepository = tslib_1.__decorate([
|
|
18
|
+
exports.TodoListRepository = TodoListRepository = tslib_1.__decorate([
|
|
19
19
|
tslib_1.__param(0, (0, core_1.inject)('datasources.primary')),
|
|
20
20
|
tslib_1.__param(1, repository_1.repository.getter('TodoRepository')),
|
|
21
21
|
tslib_1.__metadata("design:paramtypes", [primary_datasource_1.PrimaryDataSource, Function])
|
|
22
22
|
], TodoListRepository);
|
|
23
|
-
exports.TodoListRepository = TodoListRepository;
|
|
24
23
|
//# sourceMappingURL=todo-list.repository.js.map
|
|
25
24
|
//# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/repositories/todo-list.repository.js.map
|
|
@@ -7,7 +7,7 @@ const repository_1 = require("@loopback/repository");
|
|
|
7
7
|
const sequelize_1 = require("../../../sequelize");
|
|
8
8
|
const primary_datasource_1 = require("../datasources/primary.datasource");
|
|
9
9
|
const index_1 = require("../models/index");
|
|
10
|
-
let TodoRepository = class TodoRepository extends sequelize_1.SequelizeCrudRepository {
|
|
10
|
+
let TodoRepository = exports.TodoRepository = class TodoRepository extends sequelize_1.SequelizeCrudRepository {
|
|
11
11
|
constructor(dataSource, todoListRepositoryGetter) {
|
|
12
12
|
super(index_1.Todo, dataSource);
|
|
13
13
|
this.todoListRepositoryGetter = todoListRepositoryGetter;
|
|
@@ -15,11 +15,10 @@ let TodoRepository = class TodoRepository extends sequelize_1.SequelizeCrudRepos
|
|
|
15
15
|
this.registerInclusionResolver('todoList', this.todoList.inclusionResolver);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
-
TodoRepository = tslib_1.__decorate([
|
|
18
|
+
exports.TodoRepository = TodoRepository = tslib_1.__decorate([
|
|
19
19
|
tslib_1.__param(0, (0, core_1.inject)('datasources.primary')),
|
|
20
20
|
tslib_1.__param(1, repository_1.repository.getter('TodoListRepository')),
|
|
21
21
|
tslib_1.__metadata("design:paramtypes", [primary_datasource_1.PrimaryDataSource, Function])
|
|
22
22
|
], TodoRepository);
|
|
23
|
-
exports.TodoRepository = TodoRepository;
|
|
24
23
|
//# sourceMappingURL=todo.repository.js.map
|
|
25
24
|
//# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/repositories/todo.repository.js.map
|
|
@@ -7,7 +7,7 @@ const repository_1 = require("@loopback/repository");
|
|
|
7
7
|
const sequelize_1 = require("../../../sequelize");
|
|
8
8
|
const primary_datasource_1 = require("../datasources/primary.datasource");
|
|
9
9
|
const index_1 = require("../models/index");
|
|
10
|
-
let UserRepository = class UserRepository extends sequelize_1.SequelizeCrudRepository {
|
|
10
|
+
let UserRepository = exports.UserRepository = class UserRepository extends sequelize_1.SequelizeCrudRepository {
|
|
11
11
|
constructor(dataSource, todoListRepositoryGetter) {
|
|
12
12
|
super(index_1.User, dataSource);
|
|
13
13
|
this.todoListRepositoryGetter = todoListRepositoryGetter;
|
|
@@ -15,11 +15,10 @@ let UserRepository = class UserRepository extends sequelize_1.SequelizeCrudRepos
|
|
|
15
15
|
this.registerInclusionResolver('todoList', this.todoList.inclusionResolver);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
-
UserRepository = tslib_1.__decorate([
|
|
18
|
+
exports.UserRepository = UserRepository = tslib_1.__decorate([
|
|
19
19
|
tslib_1.__param(0, (0, core_1.inject)('datasources.primary')),
|
|
20
20
|
tslib_1.__param(1, repository_1.repository.getter('TodoListRepository')),
|
|
21
21
|
tslib_1.__metadata("design:paramtypes", [primary_datasource_1.PrimaryDataSource, Function])
|
|
22
22
|
], UserRepository);
|
|
23
|
-
exports.UserRepository = UserRepository;
|
|
24
23
|
//# sourceMappingURL=user.repository.js.map
|
|
25
24
|
//# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/repositories/user.repository.js.map
|
package/dist/component.js
CHANGED
|
@@ -10,13 +10,13 @@ const core_1 = require("@loopback/core");
|
|
|
10
10
|
const keys_1 = require("./keys");
|
|
11
11
|
const types_1 = require("./types");
|
|
12
12
|
// Configure the binding for LoopbackSequelizeComponent
|
|
13
|
-
let LoopbackSequelizeComponent = class LoopbackSequelizeComponent {
|
|
13
|
+
let LoopbackSequelizeComponent = exports.LoopbackSequelizeComponent = class LoopbackSequelizeComponent {
|
|
14
14
|
constructor(application, options = types_1.DEFAULT_LOOPBACK_SEQUELIZE_OPTIONS) {
|
|
15
15
|
this.application = application;
|
|
16
16
|
this.options = options;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
LoopbackSequelizeComponent = tslib_1.__decorate([
|
|
19
|
+
exports.LoopbackSequelizeComponent = LoopbackSequelizeComponent = tslib_1.__decorate([
|
|
20
20
|
(0, core_1.injectable)({
|
|
21
21
|
tags: {
|
|
22
22
|
[core_1.ContextTags.KEY]: keys_1.LoopbackSequelizeComponentBindings.COMPONENT,
|
|
@@ -26,5 +26,4 @@ LoopbackSequelizeComponent = tslib_1.__decorate([
|
|
|
26
26
|
tslib_1.__param(1, (0, core_1.config)()),
|
|
27
27
|
tslib_1.__metadata("design:paramtypes", [core_1.Application, Object])
|
|
28
28
|
], LoopbackSequelizeComponent);
|
|
29
|
-
exports.LoopbackSequelizeComponent = LoopbackSequelizeComponent;
|
|
30
29
|
//# sourceMappingURL=component.js.map
|
package/dist/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAQwB;AACxB,iCAA0D;AAC1D,mCAGiB;AAEjB,uDAAuD;AAMhD,IAAM,0BAA0B,
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAQwB;AACxB,iCAA0D;AAC1D,mCAGiB;AAEjB,uDAAuD;AAMhD,IAAM,0BAA0B,wCAAhC,MAAM,0BAA0B;IACrC,YAEU,WAAwB,EAExB,UAA6C,0CAAkC;QAF/E,gBAAW,GAAX,WAAW,CAAa;QAExB,YAAO,GAAP,OAAO,CAAwE;IACtF,CAAC;CACL,CAAA;qCAPY,0BAA0B;IALtC,IAAA,iBAAU,EAAC;QACV,IAAI,EAAE;YACJ,CAAC,kBAAW,CAAC,GAAG,CAAC,EAAE,yCAAkC,CAAC,SAAS;SAChE;KACF,CAAC;IAGG,mBAAA,IAAA,aAAM,EAAC,mBAAY,CAAC,oBAAoB,CAAC,CAAA;IAEzC,mBAAA,IAAA,aAAM,GAAE,CAAA;6CADY,kBAAW;GAHvB,0BAA0B,CAOtC"}
|
package/dist/keys.js
CHANGED
|
@@ -12,5 +12,5 @@ const core_1 = require("@loopback/core");
|
|
|
12
12
|
var LoopbackSequelizeComponentBindings;
|
|
13
13
|
(function (LoopbackSequelizeComponentBindings) {
|
|
14
14
|
LoopbackSequelizeComponentBindings.COMPONENT = core_1.BindingKey.create(`${core_1.CoreBindings.COMPONENTS}.LoopbackSequelizeComponent`);
|
|
15
|
-
})(LoopbackSequelizeComponentBindings
|
|
15
|
+
})(LoopbackSequelizeComponentBindings || (exports.LoopbackSequelizeComponentBindings = LoopbackSequelizeComponentBindings = {}));
|
|
16
16
|
//# sourceMappingURL=keys.js.map
|
package/dist/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,yCAAwD;AAGxD;;GAEG;AACH,IAAiB,kCAAkC,CAIlD;AAJD,WAAiB,kCAAkC;IACpC,4CAAS,GAAG,iBAAU,CAAC,MAAM,CACxC,GAAG,mBAAY,CAAC,UAAU,6BAA6B,CACxD,CAAC;AACJ,CAAC,EAJgB,kCAAkC,
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,yCAAwD;AAGxD;;GAEG;AACH,IAAiB,kCAAkC,CAIlD;AAJD,WAAiB,kCAAkC;IACpC,4CAAS,GAAG,iBAAU,CAAC,MAAM,CACxC,GAAG,mBAAY,CAAC,UAAU,6BAA6B,CACxD,CAAC;AACJ,CAAC,EAJgB,kCAAkC,kDAAlC,kCAAkC,QAIlD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LifeCycleObserver } from '@loopback/core';
|
|
2
|
-
import { AnyObject } from '@loopback/repository';
|
|
2
|
+
import { AnyObject, Command, NamedParameters, Options, PositionalParameters } from '@loopback/repository';
|
|
3
3
|
import { PoolOptions, Sequelize, Options as SequelizeOptions, Transaction, TransactionOptions } from 'sequelize';
|
|
4
4
|
import { SupportedLoopbackConnectors } from './connector-mapping';
|
|
5
5
|
/**
|
|
@@ -11,7 +11,7 @@ export declare class SequelizeDataSource implements LifeCycleObserver {
|
|
|
11
11
|
settings: {};
|
|
12
12
|
constructor(config: SequelizeDataSourceConfig);
|
|
13
13
|
sequelize?: Sequelize;
|
|
14
|
-
sequelizeConfig:
|
|
14
|
+
sequelizeConfig: SequelizeOptions;
|
|
15
15
|
init(): Promise<void>;
|
|
16
16
|
start(..._injectedArgs: unknown[]): Promise<void>;
|
|
17
17
|
stop(): Promise<void>;
|
|
@@ -24,11 +24,62 @@ export declare class SequelizeDataSource implements LifeCycleObserver {
|
|
|
24
24
|
* @returns A promise which resolves to a Sequelize Transaction object
|
|
25
25
|
*/
|
|
26
26
|
beginTransaction(options?: TransactionOptions | TransactionOptions['isolationLevel']): Promise<Transaction>;
|
|
27
|
+
/**
|
|
28
|
+
* Execute a SQL command.
|
|
29
|
+
*
|
|
30
|
+
* **WARNING:** In general, it is always better to perform database actions
|
|
31
|
+
* through repository methods. Directly executing SQL may lead to unexpected
|
|
32
|
+
* results, corrupted data, security vulnerabilities and other issues.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* // MySQL
|
|
38
|
+
* const result = await db.execute(
|
|
39
|
+
* 'SELECT * FROM Products WHERE size > ?',
|
|
40
|
+
* [42]
|
|
41
|
+
* );
|
|
42
|
+
*
|
|
43
|
+
* // PostgreSQL
|
|
44
|
+
* const result = await db.execute(
|
|
45
|
+
* 'SELECT * FROM Products WHERE size > $1',
|
|
46
|
+
* [42]
|
|
47
|
+
* );
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param command A parameterized SQL command or query.
|
|
51
|
+
* @param parameters List of parameter values to use.
|
|
52
|
+
* @param options Additional options, for example `transaction`.
|
|
53
|
+
* @returns A promise which resolves to the command output. The output type (data structure) is database specific and
|
|
54
|
+
* often depends on the command executed.
|
|
55
|
+
*/
|
|
56
|
+
execute(command: Command, parameters?: NamedParameters | PositionalParameters, options?: Options): Promise<AnyObject>;
|
|
27
57
|
getPoolOptions(): PoolOptions | undefined;
|
|
28
58
|
}
|
|
29
|
-
export type SequelizeDataSourceConfig =
|
|
59
|
+
export type SequelizeDataSourceConfig = {
|
|
30
60
|
name?: string;
|
|
31
61
|
user?: string;
|
|
32
62
|
connector?: SupportedLoopbackConnectors;
|
|
33
63
|
url?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Additional sequelize options that are passed directly to
|
|
66
|
+
* Sequelize when initializing the connection.
|
|
67
|
+
* Any options provided in this way will take priority over
|
|
68
|
+
* other configurations that may come from parsing the loopback style configurations.
|
|
69
|
+
*
|
|
70
|
+
* eg.
|
|
71
|
+
* ```ts
|
|
72
|
+
* let config = {
|
|
73
|
+
* name: 'db',
|
|
74
|
+
* connector: 'postgresql',
|
|
75
|
+
* sequelizeOptions: {
|
|
76
|
+
* dialectOptions: {
|
|
77
|
+
* rejectUnauthorized: false,
|
|
78
|
+
* ca: fs.readFileSync('/path/to/root.crt').toString(),
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* };
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
sequelizeOptions?: SequelizeOptions;
|
|
34
85
|
} & AnyObject;
|
|
@@ -22,7 +22,7 @@ class SequelizeDataSource {
|
|
|
22
22
|
}
|
|
23
23
|
async init() {
|
|
24
24
|
const { config } = this;
|
|
25
|
-
const { connector, file, schema, database, host, port, user, username, password, } = config;
|
|
25
|
+
const { connector, file, schema, database, host, port, user, username, password, tns, } = config;
|
|
26
26
|
this.sequelizeConfig = {
|
|
27
27
|
database,
|
|
28
28
|
dialect: connector ? connector_mapping_1.SupportedConnectorMapping[connector] : undefined,
|
|
@@ -34,8 +34,17 @@ class SequelizeDataSource {
|
|
|
34
34
|
password,
|
|
35
35
|
logging: queryLogging,
|
|
36
36
|
pool: this.getPoolOptions(),
|
|
37
|
+
dialectOptions: {
|
|
38
|
+
connectString: tns, // oracle connect string
|
|
39
|
+
},
|
|
40
|
+
...config.sequelizeOptions,
|
|
37
41
|
};
|
|
38
|
-
|
|
42
|
+
if (config.url) {
|
|
43
|
+
this.sequelize = new sequelize_1.Sequelize(config.url, this.sequelizeConfig);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.sequelize = new sequelize_1.Sequelize(this.sequelizeConfig);
|
|
47
|
+
}
|
|
39
48
|
await this.sequelize.authenticate();
|
|
40
49
|
debug('Connection has been established successfully.');
|
|
41
50
|
}
|
|
@@ -80,6 +89,70 @@ class SequelizeDataSource {
|
|
|
80
89
|
}
|
|
81
90
|
return this.sequelize.transaction(options);
|
|
82
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Execute a SQL command.
|
|
94
|
+
*
|
|
95
|
+
* **WARNING:** In general, it is always better to perform database actions
|
|
96
|
+
* through repository methods. Directly executing SQL may lead to unexpected
|
|
97
|
+
* results, corrupted data, security vulnerabilities and other issues.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
*
|
|
101
|
+
* ```ts
|
|
102
|
+
* // MySQL
|
|
103
|
+
* const result = await db.execute(
|
|
104
|
+
* 'SELECT * FROM Products WHERE size > ?',
|
|
105
|
+
* [42]
|
|
106
|
+
* );
|
|
107
|
+
*
|
|
108
|
+
* // PostgreSQL
|
|
109
|
+
* const result = await db.execute(
|
|
110
|
+
* 'SELECT * FROM Products WHERE size > $1',
|
|
111
|
+
* [42]
|
|
112
|
+
* );
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @param command A parameterized SQL command or query.
|
|
116
|
+
* @param parameters List of parameter values to use.
|
|
117
|
+
* @param options Additional options, for example `transaction`.
|
|
118
|
+
* @returns A promise which resolves to the command output. The output type (data structure) is database specific and
|
|
119
|
+
* often depends on the command executed.
|
|
120
|
+
*/
|
|
121
|
+
async execute(command, parameters, options) {
|
|
122
|
+
if (!this.sequelize) {
|
|
123
|
+
throw Error(`The datasource "${this.name}" doesn't have sequelize instance bound to it.`);
|
|
124
|
+
}
|
|
125
|
+
if (typeof command !== 'string') {
|
|
126
|
+
command = JSON.stringify(command);
|
|
127
|
+
}
|
|
128
|
+
options = options !== null && options !== void 0 ? options : {};
|
|
129
|
+
const queryOptions = {};
|
|
130
|
+
if (options === null || options === void 0 ? void 0 : options.transaction) {
|
|
131
|
+
queryOptions.transaction = options.transaction;
|
|
132
|
+
}
|
|
133
|
+
let targetReplacementKey;
|
|
134
|
+
// By default, we'll use 'bind'
|
|
135
|
+
targetReplacementKey = 'bind';
|
|
136
|
+
if (command.includes('?')) {
|
|
137
|
+
// If command has '?', use 'replacements'
|
|
138
|
+
targetReplacementKey = 'replacements';
|
|
139
|
+
}
|
|
140
|
+
else if (/\$\w/g.test(command)) {
|
|
141
|
+
// If command has parameters starting with a dollar sign ($param or $1, $2), use 'bind'
|
|
142
|
+
targetReplacementKey = 'bind';
|
|
143
|
+
}
|
|
144
|
+
if (parameters) {
|
|
145
|
+
queryOptions[targetReplacementKey] = parameters;
|
|
146
|
+
}
|
|
147
|
+
const result = await this.sequelize.query(command, queryOptions);
|
|
148
|
+
// Sequelize returns the select query result in an array at index 0 and at index 1 is the actual Result instance
|
|
149
|
+
// Whereas in juggler it is returned directly as plain array.
|
|
150
|
+
// Below condition maps that 0th index to final result to match juggler's behaviour
|
|
151
|
+
if (command.match(/^select/i) && result.length >= 1) {
|
|
152
|
+
return result[0];
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
83
156
|
getPoolOptions() {
|
|
84
157
|
const config = this.config;
|
|
85
158
|
const specifiedPoolOptions = Object.keys(config).some(key => connector_mapping_1.poolConfigKeys.includes(key));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequelize.datasource.base.js","sourceRoot":"","sources":["../../src/sequelize/sequelize.datasource.base.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"sequelize.datasource.base.js","sourceRoot":"","sources":["../../src/sequelize/sequelize.datasource.base.ts"],"names":[],"mappings":";;;;AAQA,0DAAiC;AACjC,yCAOmB;AACnB,2DAQ6B;AAE7B,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,+BAA+B,CAAC,CAAC;AAC5D,MAAM,YAAY,GAAG,IAAA,eAAY,EAAC,4BAA4B,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAa,mBAAmB;IAG9B,YAAmB,MAAiC;;QAAjC,WAAM,GAAN,MAAM,CAA2B;QADpD,aAAQ,GAAG,EAAE,CAAC;QAEZ,IACE,IAAI,CAAC,MAAM,CAAC,SAAS;YACrB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,6CAAyB,CAAC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AErE,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO;SACR;QAED,MAAM,EAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAC,GAAG,aAAa,CAAC;QAChD,MAAM,OAAO,GAAgB,EAAE,CAAC;QAChC,IAAI,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;YACtB,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;SAC3B;QACD,IAAI,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;YACtB,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;SAC3B;QACD,IAAI,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE;YAC9B,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;SACnC;QACD,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE;YACxB,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;SAC7B;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AA7ND,kDA6NC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject, BelongsToAccessor, Count, DataObject, Entity, EntityCrudRepository, Fields, Filter, FilterExcludingWhere, Getter, HasManyRepositoryFactory, HasManyThroughRepositoryFactory, HasOneRepositoryFactory, InclusionFilter, InclusionResolver, PositionalParameters, PropertyDefinition, ReferencesManyAccessor, Where } from '@loopback/repository';
|
|
1
|
+
import { AnyObject, BelongsToAccessor, Command, Count, DataObject, Entity, EntityCrudRepository, Fields, Filter, FilterExcludingWhere, Getter, HasManyRepositoryFactory, HasManyThroughRepositoryFactory, HasOneRepositoryFactory, InclusionFilter, InclusionResolver, NamedParameters, Options, PositionalParameters, PropertyDefinition, ReferencesManyAccessor, Where } from '@loopback/repository';
|
|
2
2
|
import { Attributes, FindAttributeOptions, Includeable, Model, ModelAttributes, ModelStatic, Order, SyncOptions, Transaction, TransactionOptions, WhereOptions } from 'sequelize';
|
|
3
3
|
import { operatorTranslations } from './operator-translation';
|
|
4
4
|
import { SequelizeDataSource } from './sequelize.datasource.base';
|
|
@@ -34,6 +34,17 @@ export declare class SequelizeCrudRepository<T extends Entity, ID, Relations ext
|
|
|
34
34
|
* This array of keys is used while building model definition for sequelize.
|
|
35
35
|
*/
|
|
36
36
|
readonly DB_SPECIFIC_SETTINGS_KEYS: readonly ["postgresql", "mysql", "sqlite3"];
|
|
37
|
+
/**
|
|
38
|
+
* Length of the `nanoid` generated for defaultFn's `shortid` and `nanoid` aliases.
|
|
39
|
+
*/
|
|
40
|
+
NANO_ID_LENGTH: number;
|
|
41
|
+
/**
|
|
42
|
+
* The alias registry for `defaultFn` option used in model property definition.
|
|
43
|
+
*
|
|
44
|
+
* See: https://loopback.io/doc/en/lb4/Model.html#property-decorator
|
|
45
|
+
*/
|
|
46
|
+
protected defaultFnRegistry: Record<string, unknown>;
|
|
47
|
+
protected getDefaultFnRegistry(): Record<string, unknown>;
|
|
37
48
|
readonly inclusionResolvers: Map<string, InclusionResolver<T, Entity>>;
|
|
38
49
|
/**
|
|
39
50
|
* Sequelize Model Instance created from the model definition received from the `entityClass`
|
|
@@ -54,7 +65,36 @@ export declare class SequelizeCrudRepository<T extends Entity, ID, Relations ext
|
|
|
54
65
|
deleteAll(where?: Where<T> | undefined, options?: AnyObject | undefined): Promise<Count>;
|
|
55
66
|
deleteById(id: ID, options?: AnyObject | undefined): Promise<void>;
|
|
56
67
|
count(where?: Where<T>, options?: AnyObject): Promise<Count>;
|
|
57
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Execute a SQL command.
|
|
70
|
+
*
|
|
71
|
+
* **WARNING:** In general, it is always better to perform database actions
|
|
72
|
+
* through repository methods. Directly executing SQL may lead to unexpected
|
|
73
|
+
* results, corrupted data, security vulnerabilities and other issues.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* // MySQL
|
|
79
|
+
* const result = await repo.execute(
|
|
80
|
+
* 'SELECT * FROM Products WHERE size > ?',
|
|
81
|
+
* [42]
|
|
82
|
+
* );
|
|
83
|
+
*
|
|
84
|
+
* // PostgreSQL
|
|
85
|
+
* const result = await repo.execute(
|
|
86
|
+
* 'SELECT * FROM Products WHERE size > $1',
|
|
87
|
+
* [42]
|
|
88
|
+
* );
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param command A parameterized SQL command or query.
|
|
92
|
+
* @param parameters List of parameter values to use.
|
|
93
|
+
* @param options Additional options, for example `transaction`.
|
|
94
|
+
* @returns A promise which resolves to the command output. The output type (data structure) is database specific and
|
|
95
|
+
* often depends on the command executed.
|
|
96
|
+
*/
|
|
97
|
+
execute(command: Command, parameters?: NamedParameters | PositionalParameters, options?: Options): Promise<AnyObject>;
|
|
58
98
|
protected toEntities(models: Model<T, T>[]): T[];
|
|
59
99
|
/**
|
|
60
100
|
* Get Sequelize Operator
|
|
@@ -74,6 +114,13 @@ export declare class SequelizeCrudRepository<T extends Entity, ID, Relations ext
|
|
|
74
114
|
* @returns Sequelize compatible order filter value
|
|
75
115
|
*/
|
|
76
116
|
protected buildSequelizeOrder(order?: string[] | string): Order | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Checks if the resolver of the inclusion relation is registered
|
|
119
|
+
* in the inclusionResolver of the current repository
|
|
120
|
+
*
|
|
121
|
+
* @param include - LoopBack Inclusion filter
|
|
122
|
+
*/
|
|
123
|
+
protected isInclusionAllowed(include: InclusionFilter): boolean;
|
|
77
124
|
/**
|
|
78
125
|
* Build Sequelize compatible `include` filter
|
|
79
126
|
* @param inclusionFilters - loopback style `where` condition
|
|
@@ -95,7 +142,22 @@ export declare class SequelizeCrudRepository<T extends Entity, ID, Relations ext
|
|
|
95
142
|
*/
|
|
96
143
|
getSequelizeModel(entityClass?: typeof Entity & {
|
|
97
144
|
prototype: T;
|
|
98
|
-
}): import("sequelize").ModelCtor<Model<any, any
|
|
145
|
+
}): import("sequelize").ModelCtor<Model<any, any>>;
|
|
146
|
+
/**
|
|
147
|
+
* This function retrieves the table name associated with a given entity class.
|
|
148
|
+
* Different loopback connectors have different conventions for picking up table names,
|
|
149
|
+
* unless the name is specified in the @model decorator.
|
|
150
|
+
*
|
|
151
|
+
* The function follows the following cases to determine the table name:
|
|
152
|
+
* - It checks if the name property is specified in the @model decorator and uses it. (this takes precedence over all other cases)
|
|
153
|
+
* - If the dialect of the dataSource is PostgreSQL, it uses the lowercased version of the model class name.
|
|
154
|
+
* - If the dialect is MySQL or any other dialect, it uses the default model class name.
|
|
155
|
+
* @param {Entity} entityClass - The entity class for which the table name is being retrieved.
|
|
156
|
+
* @returns {string} - The table name associated with the entity class. Which is used when performing the query.
|
|
157
|
+
*/
|
|
158
|
+
getTableName(entityClass?: typeof Entity & {
|
|
159
|
+
prototype: T;
|
|
160
|
+
}): string;
|
|
99
161
|
/**
|
|
100
162
|
* Run CREATE TABLE query for the target sequelize model, Useful for quick testing
|
|
101
163
|
* @param options Sequelize Sync Options
|
|
@@ -120,6 +182,11 @@ export declare class SequelizeCrudRepository<T extends Entity, ID, Relations ext
|
|
|
120
182
|
* Remove hidden properties specified in model from response body. (See: https://github.com/sourcefuse/loopback4-sequelize/issues/3)
|
|
121
183
|
* @param entity normalized entity. You can use `entity.toJSON()`'s value
|
|
122
184
|
* @returns normalized entity excluding the hiddenProperties
|
|
185
|
+
*
|
|
186
|
+
* @deprecated To exclude hidden props from an entity instance, call the `.toJSON()` method on it.
|
|
187
|
+
* Alternatively it can be use by manually instantiating the model using `new EntityClass(data).toJSON()`.
|
|
188
|
+
*
|
|
189
|
+
* This function will be removed in next major release.
|
|
123
190
|
*/
|
|
124
191
|
protected excludeHiddenProps(entity: T & Relations): T & Relations;
|
|
125
192
|
/**
|