@homeofthings/nestjs-sqlite3
Advanced tools
Comparing version 1.0.5 to 2.0.0
# CHANGELOG | ||
| Release | Notes | | ||
| ------- | --------------------- | | ||
|---------|-----------------------| | ||
| 2.0.0 | nestjs 10x | | ||
| 1.0.4-4 | maintenance release | | ||
| 1.0.3 | repository: finde one | | ||
| 1.0.2 | first version | |
{ | ||
"name": "@homeofthings/nestjs-sqlite3", | ||
"description": "HomeOfThings - NestJs Sqlite3: Sqlite3 module for NestJs based on 'sqlite3orm'", | ||
"version": "1.0.5", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
@@ -30,14 +30,13 @@ "nestjs", | ||
"homepage": "https://github.com/gms1/HomeOfThings", | ||
"dependencies": { | ||
"@homeofthings/nestjs-utils": "*", | ||
"@nestjs/common": "*", | ||
"@nestjs/core": "*", | ||
"reflect-metadata": "*", | ||
"rxjs": "*", | ||
"sqlite3orm": "*", | ||
"tslib": "*" | ||
}, | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts", | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"reflect-metadata": "^0.1.13", | ||
"@homeofthings/nestjs-utils": "1.0.6", | ||
"@nestjs/common": "^8.4.7", | ||
"rxjs": "~7.5.5", | ||
"sqlite3orm": "^2.6.4", | ||
"@nestjs/core": "^8.4.7", | ||
"tslib": "^2.4.0" | ||
} | ||
} | ||
"type": "commonjs" | ||
} |
[![npm version](https://badge.fury.io/js/%40homeofthings%2Fnestjs-sqlite3.svg)](https://badge.fury.io/js/%40homeofthings%2Fnestjs-sqlite3) | ||
[![Build Workflow](https://github.com/gms1/HomeOfThings/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/gms1/HomeOfThings/actions/workflows/build.yml) | ||
[![Coverage Status](https://codecov.io/gh/gms1/HomeOfThings/branch/master/graph/badge.svg?flag=nestjs-sqlite3)](https://codecov.io/gh/gms1/HomeOfThings) | ||
[![Coverage Status](https://codecov.io/gh/gms1/HomeOfThings/branch/master/graph/badge.svg?flag=nestjs-sqlite3)](https://app.codecov.io/gh/gms1/HomeOfThings/tree/master/packages%2Fnode%2F%40homeofthings%2Fnestjs-sqlite3) | ||
[![DeepScan grade](https://deepscan.io/api/teams/439/projects/987/branches/1954/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=439&pid=987&bid=1954) | ||
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) | ||
[![License](https://img.shields.io/npm/l/@homeofthings/nestjs-sqlite3.svg?style=flat-square)](https://github.com/gms1/HomeOfThings/blob/master/LICENSE) | ||
[![License](https://img.shields.io/npm/l/@homeofthings/nestjs-sqlite3.svg?style=flat-square)](https://github.com/gms1/HomeOfThings/blob/master/packages/node/@homeofthings/nestjs-sqlite3/LICENSE) | ||
@@ -46,3 +46,3 @@ # HomeOfThings - Sqlite3 for NestJs | ||
imports: [], // optional | ||
useFactory: (): Promise<Sqlite3ModuleOptions> => Promise.resolve({ | ||
useFactory: (): Promise<Sqlite3ConnectionOptions> => Promise.resolve({ | ||
// provide your options | ||
@@ -49,0 +49,0 @@ }), |
@@ -10,5 +10,5 @@ import 'reflect-metadata'; | ||
export declare const ForeignKey: typeof fk; | ||
export declare const InjectConnectionPool: (connection?: string) => (target: object, key: string | symbol, index?: number) => void; | ||
export declare const InjectEntityManager: (connection?: string) => (target: object, key: string | symbol, index?: number) => void; | ||
export declare const InjectRepository: (entity: Type, connection?: string) => (target: object, key: string | symbol, index?: number) => void; | ||
export declare const InjectCustomRepository: (repository: RepositoryType, connection?: string) => (target: object, key: string | symbol, index?: number) => void; | ||
export declare const InjectConnectionPool: (connection?: string) => PropertyDecorator & ParameterDecorator; | ||
export declare const InjectEntityManager: (connection?: string) => PropertyDecorator & ParameterDecorator; | ||
export declare const InjectRepository: (entity: Type, connection?: string) => PropertyDecorator & ParameterDecorator; | ||
export declare const InjectCustomRepository: (repository: RepositoryType, connection?: string) => PropertyDecorator & ParameterDecorator; |
@@ -8,8 +8,8 @@ import { GenericDictionary } from '@homeofthings/nestjs-utils'; | ||
export * from './sqlite3.options'; | ||
export declare type Sqlite3ConnectionsOptions = GenericDictionary<Sqlite3ConnectionOptions>; | ||
export declare type Sqlite3ConnectionPools = GenericDictionary<SqlConnectionPool>; | ||
export declare type Sqlite3Connections = GenericDictionary<SqlDatabase | undefined>; | ||
export declare type Sqlite3EntityManagers = GenericDictionary<EntityManager>; | ||
export type Sqlite3ConnectionsOptions = GenericDictionary<Sqlite3ConnectionOptions>; | ||
export type Sqlite3ConnectionPools = GenericDictionary<SqlConnectionPool>; | ||
export type Sqlite3Connections = GenericDictionary<SqlDatabase | undefined>; | ||
export type Sqlite3EntityManagers = GenericDictionary<EntityManager>; | ||
export interface RepositoryType<T = Repository<any>> extends Function { | ||
new (connectionManager: ConnectionManager, connectionName: string): T; | ||
} |
@@ -11,8 +11,12 @@ "use strict"; | ||
const entity_manager_1 = require("./entity-manager"); | ||
let ConnectionManager = ConnectionManager_1 = class ConnectionManager { | ||
let ConnectionManager = class ConnectionManager { | ||
static { ConnectionManager_1 = this; } | ||
static _instance; | ||
static tablesPerConnection; | ||
logger = new common_1.Logger('ConnectionManager'); | ||
_connectionPools = {}; | ||
_entityManagers = {}; | ||
_context; | ||
_warnOnOpenConnectionsInCreateConnectionContext = true; | ||
constructor() { | ||
this.logger = new common_1.Logger('ConnectionManager'); | ||
this._connectionPools = {}; | ||
this._entityManagers = {}; | ||
this._warnOnOpenConnectionsInCreateConnectionContext = true; | ||
if (ConnectionManager_1._instance) { | ||
@@ -104,19 +108,17 @@ throw new Error(`an instance of ConnectionManager is already initialized`); | ||
} | ||
closeConnectionContext(_commit) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const connectionDictionary = this._context.get(); | ||
this._context.set({}); | ||
if (!connectionDictionary) { | ||
return Promise.resolve(); | ||
} | ||
const connections = Object.keys(connectionDictionary) | ||
.filter((name) => connectionDictionary[name]) | ||
.map((name) => connectionDictionary[name]); | ||
if (_commit) { | ||
yield Promise.allSettled(connections.map((connection) => connection.endTransaction(_commit))); | ||
} | ||
return Promise.allSettled( | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
connections.map((connection) => connection.close())).then(() => Promise.resolve()); | ||
}); | ||
async closeConnectionContext(_commit) { | ||
const connectionDictionary = this._context.get(); | ||
this._context.set({}); | ||
if (!connectionDictionary) { | ||
return Promise.resolve(); | ||
} | ||
const connections = Object.keys(connectionDictionary) | ||
.filter((name) => connectionDictionary[name]) | ||
.map((name) => connectionDictionary[name]); | ||
if (_commit) { | ||
await Promise.allSettled(connections.map((connection) => connection.endTransaction(_commit))); | ||
} | ||
return Promise.allSettled( | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
connections.map((connection) => connection.close())).then(() => Promise.resolve()); | ||
} | ||
@@ -177,4 +179,3 @@ getConnection(name) { | ||
static getTables(connectionName = model_1.SQLITE3_DEFAULT_CONNECTION_NAME) { | ||
var _a; | ||
if (!((_a = this.tablesPerConnection) === null || _a === void 0 ? void 0 : _a[connectionName])) { | ||
if (!this.tablesPerConnection?.[connectionName]) { | ||
return []; | ||
@@ -185,7 +186,7 @@ } | ||
}; | ||
ConnectionManager = ConnectionManager_1 = tslib_1.__decorate([ | ||
exports.ConnectionManager = ConnectionManager; | ||
exports.ConnectionManager = ConnectionManager = ConnectionManager_1 = tslib_1.__decorate([ | ||
(0, common_1.Injectable)(), | ||
tslib_1.__metadata("design:paramtypes", []) | ||
], ConnectionManager); | ||
exports.ConnectionManager = ConnectionManager; | ||
//# sourceMappingURL=connection-manager.js.map |
@@ -18,3 +18,3 @@ import { Type } from '@homeofthings/nestjs-utils'; | ||
*/ | ||
getRepository<T>(entity: Type<T>): Promise<Repository<T>>; | ||
getRepository<T extends Object>(entity: Type<T>): Promise<Repository<T>>; | ||
/** | ||
@@ -39,3 +39,3 @@ * get a custom repository for the given repository class value | ||
*/ | ||
exists<T>(entity: Type<T>, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<boolean>; | ||
exists<T extends Object>(entity: Type<T>, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<boolean>; | ||
/** | ||
@@ -52,3 +52,3 @@ * count all rows using an optional filter | ||
*/ | ||
count<T>(entity: Type<T>, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<number>; | ||
count<T extends Object>(entity: Type<T>, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<number>; | ||
/** | ||
@@ -62,3 +62,3 @@ * find entity by primary key | ||
*/ | ||
findById<T>(entity: Type<T>, input: Partial<T>): Promise<T>; | ||
findById<T extends Object>(entity: Type<T>, input: Partial<T>): Promise<T>; | ||
/** | ||
@@ -72,3 +72,3 @@ * find one entity | ||
*/ | ||
findOne<T>(entity: Type<T>, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<T>; | ||
findOne<T extends Object>(entity: Type<T>, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<T>; | ||
/** | ||
@@ -85,3 +85,3 @@ * find all entities using an optional filter | ||
*/ | ||
findAll<T>(entity: Type<T>, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<T[]>; | ||
findAll<T extends Object>(entity: Type<T>, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<T[]>; | ||
/** | ||
@@ -97,3 +97,3 @@ * find parent entity by using a foreign key constraint and a given child instance | ||
*/ | ||
findByChild<T, C extends Object>(entity: Type<T>, constraintName: string, childEntity: Type<C>, childObj: C): Promise<T>; | ||
findByChild<T extends Object, C extends Object>(entity: Type<T>, constraintName: string, childEntity: Type<C>, childObj: C): Promise<T>; | ||
/** | ||
@@ -112,3 +112,3 @@ * find all child entities using a foreign key constraint and a given parent instance | ||
*/ | ||
findAllByParent<T, P extends Object>(entity: Type<T>, constraintName: string, parentEntity: Type<P>, parentObj: P, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<T[]>; | ||
findAllByParent<T extends Object, P extends Object>(entity: Type<T>, constraintName: string, parentEntity: Type<P>, parentObj: P, whereOrFilter?: Where<T> | Filter<T>, params?: Object): Promise<T[]>; | ||
/** | ||
@@ -124,3 +124,3 @@ * save - Saves a given entity. | ||
*/ | ||
save<T>(entity: Type<T>, model: T): Promise<T>; | ||
save<T extends Object>(entity: Type<T>, model: T): Promise<T>; | ||
/** | ||
@@ -138,3 +138,3 @@ * save partially - save (insert or update) only columns mapped to the property keys from the partial input | ||
*/ | ||
savePartial<T>(entity: Type<T>, input: Partial<T>): Promise<Partial<T>>; | ||
savePartial<T extends Object>(entity: Type<T>, input: Partial<T>): Promise<Partial<T>>; | ||
/** | ||
@@ -149,3 +149,3 @@ * insert | ||
*/ | ||
insert<T>(entity: Type<T>, model: T, mode?: BaseDAOInsertMode): Promise<T>; | ||
insert<T extends Object>(entity: Type<T>, model: T, mode?: BaseDAOInsertMode): Promise<T>; | ||
/** | ||
@@ -163,3 +163,3 @@ * insert partially - insert only columns mapped to the property keys from the partial input | ||
*/ | ||
insertPartial<T>(entity: Type<T>, input: Partial<T>, mode?: BaseDAOInsertMode): Promise<Partial<T>>; | ||
insertPartial<T extends Object>(entity: Type<T>, input: Partial<T>, mode?: BaseDAOInsertMode): Promise<Partial<T>>; | ||
/** | ||
@@ -173,3 +173,3 @@ * update | ||
*/ | ||
update<T>(entity: Type<T>, model: T): Promise<T>; | ||
update<T extends Object>(entity: Type<T>, model: T): Promise<T>; | ||
/** | ||
@@ -186,3 +186,3 @@ * update partially - update only columns mapped to the property keys from the partial input | ||
*/ | ||
updatePartial<T>(entity: Type<T>, input: Partial<T>): Promise<Partial<T>>; | ||
updatePartial<T extends Object>(entity: Type<T>, input: Partial<T>): Promise<Partial<T>>; | ||
/** | ||
@@ -204,3 +204,3 @@ * update all - please provide a proper sql-condition otherwise all records will be updated! | ||
*/ | ||
updatePartialAll<T>(entity: Type<T>, input: Partial<T>, where?: Where<T>, params?: Object): Promise<number>; | ||
updatePartialAll<T extends Object>(entity: Type<T>, input: Partial<T>, where?: Where<T>, params?: Object): Promise<number>; | ||
/** | ||
@@ -214,3 +214,3 @@ * deleteById | ||
*/ | ||
deleteById<T>(entity: Type<T>, input: Partial<T>): Promise<void>; | ||
deleteById<T extends Object>(entity: Type<T>, input: Partial<T>): Promise<void>; | ||
/** | ||
@@ -226,5 +226,5 @@ * delete all - please provide a proper sql-condition otherwise all records will be deleted! | ||
*/ | ||
deleteAll<T>(entity: Type<T>, where?: Where<T>, params?: Object): Promise<number>; | ||
deleteAll<T extends Object>(entity: Type<T>, where?: Where<T>, params?: Object): Promise<number>; | ||
private getDao; | ||
static getEntityTarget(entity: Type): string | undefined; | ||
} |
@@ -8,10 +8,12 @@ "use strict"; | ||
class EntityManager { | ||
_connectionManager; | ||
_connectionName; | ||
logger = new common_1.Logger('EntityManager'); | ||
get connection() { | ||
return this._connectionManager.getConnection(this._connectionName); | ||
} | ||
constructor(_connectionManager, _connectionName) { | ||
this._connectionManager = _connectionManager; | ||
this._connectionName = _connectionName; | ||
this.logger = new common_1.Logger('EntityManager'); | ||
} | ||
get connection() { | ||
return this._connectionManager.getConnection(this._connectionName); | ||
} | ||
/** | ||
@@ -265,3 +267,3 @@ * get a repository for the given entity class | ||
const metaModel = Reflect.getMetadata(sqlite3orm_1.METADATA_MODEL_KEY, entity.prototype); | ||
return metaModel === null || metaModel === void 0 ? void 0 : metaModel.table.quotedName; | ||
return metaModel?.table.quotedName; | ||
} | ||
@@ -268,0 +270,0 @@ } |
import { Type } from '@homeofthings/nestjs-utils'; | ||
import { BaseDAO, BaseDAOInsertMode, Filter, SqlDatabase, Where } from 'sqlite3orm'; | ||
import { ConnectionManager } from './connection-manager'; | ||
export declare class Repository<T> { | ||
export declare class Repository<T extends Object> { | ||
readonly type: Type<T>; | ||
@@ -6,0 +6,0 @@ private _connectionManager; |
@@ -7,2 +7,6 @@ "use strict"; | ||
class Repository { | ||
type; | ||
_connectionManager; | ||
_connectionName; | ||
table; | ||
constructor(type, _connectionManager, _connectionName) { | ||
@@ -9,0 +13,0 @@ this.type = type; |
@@ -9,21 +9,20 @@ "use strict"; | ||
let Sqlite3Interceptor = class Sqlite3Interceptor { | ||
connectionManager; | ||
constructor(connectionManager) { | ||
this.connectionManager = connectionManager; | ||
} | ||
intercept(context, next) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield this.connectionManager.createConnectionContext(); | ||
const release = (commit) => () => (0, rxjs_1.from)(this.connectionManager.closeConnectionContext(commit)); | ||
return next.handle().pipe((0, rxjs_1.tap)({ | ||
next: release(true), | ||
error: release(false), | ||
})); | ||
}); | ||
async intercept(context, next) { | ||
await this.connectionManager.createConnectionContext(); | ||
const release = (commit) => () => (0, rxjs_1.from)(this.connectionManager.closeConnectionContext(commit)); | ||
return next.handle().pipe((0, rxjs_1.tap)({ | ||
next: release(true), | ||
error: release(false), | ||
})); | ||
} | ||
}; | ||
Sqlite3Interceptor = tslib_1.__decorate([ | ||
exports.Sqlite3Interceptor = Sqlite3Interceptor; | ||
exports.Sqlite3Interceptor = Sqlite3Interceptor = tslib_1.__decorate([ | ||
(0, common_1.Injectable)(), | ||
tslib_1.__metadata("design:paramtypes", [connection_manager_1.ConnectionManager]) | ||
], Sqlite3Interceptor); | ||
exports.Sqlite3Interceptor = Sqlite3Interceptor; | ||
//# sourceMappingURL=sqlite3-interceptor.js.map |
@@ -9,4 +9,4 @@ import { OnApplicationShutdown } from '@nestjs/common'; | ||
constructor(moduleRef: ModuleRef); | ||
onApplicationShutdown(_signal?: string): Promise<void>; | ||
onApplicationShutdown(): Promise<void>; | ||
} | ||
export {}; |
@@ -37,18 +37,18 @@ "use strict"; | ||
let Sqlite3CoreModule = Sqlite3CoreModule_1 = class Sqlite3CoreModule extends (0, nestjs_utils_1.createDynamicRootModule)(model_1.SQLITE3_MODULE_OPTIONS_TOKEN, getSqlite3DynamicRootModuleProperties) { | ||
moduleRef; | ||
logger = new common_1.Logger('Sqlite3CoreModule'); | ||
constructor(moduleRef) { | ||
super(); | ||
this.moduleRef = moduleRef; | ||
this.logger = new common_1.Logger('Sqlite3CoreModule'); | ||
this.logger.debug('instantiated'); | ||
} | ||
onApplicationShutdown(_signal) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
this.logger.debug('shutdown'); | ||
const connectionManager = this.moduleRef.get(connection_manager_1.ConnectionManager); | ||
yield connectionManager.closeAllConnectionPools(); | ||
Sqlite3CoreModule_1.isRegistered = false; | ||
}); | ||
async onApplicationShutdown() { | ||
this.logger.debug('shutdown'); | ||
const connectionManager = this.moduleRef.get(connection_manager_1.ConnectionManager); | ||
await connectionManager.closeAllConnectionPools(); | ||
Sqlite3CoreModule_1.isRegistered = false; | ||
} | ||
}; | ||
Sqlite3CoreModule = Sqlite3CoreModule_1 = tslib_1.__decorate([ | ||
exports.Sqlite3CoreModule = Sqlite3CoreModule; | ||
exports.Sqlite3CoreModule = Sqlite3CoreModule = Sqlite3CoreModule_1 = tslib_1.__decorate([ | ||
(0, common_1.Global)(), | ||
@@ -71,3 +71,2 @@ (0, common_1.Module)({ | ||
], Sqlite3CoreModule); | ||
exports.Sqlite3CoreModule = Sqlite3CoreModule; | ||
//# sourceMappingURL=sqlite3-core.module.js.map |
@@ -55,7 +55,7 @@ "use strict"; | ||
}; | ||
Sqlite3Module = Sqlite3Module_1 = tslib_1.__decorate([ | ||
exports.Sqlite3Module = Sqlite3Module; | ||
exports.Sqlite3Module = Sqlite3Module = Sqlite3Module_1 = tslib_1.__decorate([ | ||
(0, common_1.Global)(), | ||
(0, common_1.Module)({}) | ||
], Sqlite3Module); | ||
exports.Sqlite3Module = Sqlite3Module; | ||
//# sourceMappingURL=sqlite3.module.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 7 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102700
40
1497
8
+ Added@homeofthings/nestjs-utils@*
+ Added@nestjs/common@*
+ Added@nestjs/core@*
+ Addedreflect-metadata@*
+ Addedrxjs@*
+ Addedsqlite3orm@*
+ Addedtslib@*
+ Added@homeofthings/nestjs-utils@2.0.3(transitive)
+ Added@lukeed/csprng@1.1.0(transitive)
+ Added@nestjs/common@10.4.8(transitive)
+ Added@nestjs/core@10.4.8(transitive)
+ Addedpath-to-regexp@3.3.0(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedtslib@2.7.0(transitive)
+ Addedtype-fest@4.28.0(transitive)
+ Addeduid@2.0.2(transitive)
- Removed@homeofthings/nestjs-utils@1.0.6(transitive)
- Removed@nestjs/common@8.4.7(transitive)
- Removed@nestjs/core@8.4.7(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaxios@0.27.2(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedform-data@4.0.1(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedobject-hash@3.0.0(transitive)
- Removedpath-to-regexp@3.2.0(transitive)
- Removedreflect-metadata@0.1.14(transitive)
- Removedrxjs@7.5.7(transitive)
- Removedtslib@2.4.0(transitive)
- Removedtype-fest@4.29.0(transitive)
- Removeduuid@8.3.2(transitive)