ts-redis-orm
Advanced tools
Comparing version 0.1.12 to 0.1.13
@@ -9,2 +9,3 @@ import { | ||
RedisOrmSchemaError, | ||
serviceInstance, | ||
} from "./src/"; // from "ts-redis-orm" | ||
@@ -163,2 +164,6 @@ | ||
// others | ||
const removeSchemasList = serviceInstance.getRemoveSchemasList("connectionKey"); | ||
const allEntityTypes = serviceInstance.getEntityTypes(); | ||
// errors | ||
@@ -165,0 +170,0 @@ try { |
@@ -9,2 +9,3 @@ import { BaseEntity } from "./BaseEntity"; | ||
import { Query } from "./Query"; | ||
export { Query, BaseEntity, Column, Entity, RedisOrmEntityError, RedisOrmQueryError, RedisOrmDecoratorError, RedisOrmSchemaError, }; | ||
import { serviceInstance } from "./serviceInstance"; | ||
export { Query, BaseEntity, Column, Entity, RedisOrmEntityError, RedisOrmQueryError, RedisOrmDecoratorError, RedisOrmSchemaError, serviceInstance, }; |
@@ -19,1 +19,3 @@ "use strict"; | ||
exports.Query = Query_1.Query; | ||
const serviceInstance_1 = require("./serviceInstance"); | ||
exports.serviceInstance = serviceInstance_1.serviceInstance; |
import IORedis from "ioredis"; | ||
import { IEntityMeta, ISchema } from "./types"; | ||
import { IEntityMeta, ISchema, ISchemas } from "./types"; | ||
declare class ServiceInstance { | ||
@@ -10,2 +10,3 @@ private _entityMetas; | ||
getConnectionConfig(target: object): any; | ||
getConnectionConfigByConnection(connection: string): any; | ||
getEntityMeta(target: object): IEntityMeta; | ||
@@ -43,3 +44,5 @@ getDefaultTable(target: object): string; | ||
getUniqueStorageKey(table: string, column: string): string; | ||
getMetaStorageKey(table: string): string; | ||
getSchemasStorageKey(): string; | ||
getEntityTypes(): object[]; | ||
getRemoveSchemasList(connection?: string): Promise<ISchemas>; | ||
private _registerLuaLock; | ||
@@ -46,0 +49,0 @@ private _registerLua; |
@@ -58,2 +58,5 @@ "use strict"; | ||
const connection = this.getConnection(target); | ||
return this.getConnectionConfigByConnection(connection); | ||
} | ||
getConnectionConfigByConnection(connection) { | ||
const configFile = configLoader_1.configLoader.getConfigFile(); | ||
@@ -225,5 +228,4 @@ if (!configFile) { | ||
const redis = yield exports.serviceInstance.getRedis(target); | ||
const metaStorageKey = this.getMetaStorageKey(table); | ||
const hashKey = "schemas"; | ||
const remoteSchemasString = yield redis.hget(metaStorageKey, hashKey); | ||
const storageKey = this.getSchemasStorageKey(); | ||
const remoteSchemasString = yield redis.hget(storageKey, table); | ||
if (remoteSchemasString) { | ||
@@ -246,6 +248,26 @@ return JSON.parse(remoteSchemasString); | ||
} | ||
getMetaStorageKey(table) { | ||
return `meta:${table}`; | ||
getSchemasStorageKey() { | ||
return `meta:schemas`; | ||
} | ||
// endregion | ||
// region operations | ||
getEntityTypes() { | ||
return [...this._entityMetas.keys()]; | ||
} | ||
getRemoveSchemasList(connection = "default") { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const schemasList = {}; | ||
const connectionConfig = exports.serviceInstance.getConnectionConfigByConnection(connection); | ||
if (connectionConfig) { | ||
const redis = new ioredis_1.default(connectionConfig); | ||
const storageKey = exports.serviceInstance.getSchemasStorageKey(); | ||
const result = yield redis.hgetall(storageKey); | ||
for (const [table, schemasString] of Object.entries(result)) { | ||
schemasList[table] = JSON.parse(schemasString); | ||
} | ||
} | ||
return schemasList; | ||
}); | ||
} | ||
// endregion | ||
// region private methods | ||
@@ -252,0 +274,0 @@ _registerLuaLock(target, redisContainer) { |
import * as IORedis from "ioredis"; | ||
import { BaseEntity } from "./BaseEntity"; | ||
export declare type ISchemas = { | ||
[key: string]: ISchema; | ||
}; | ||
export interface ISchemaBase { | ||
@@ -4,0 +7,0 @@ primary: boolean; |
{ | ||
"name": "ts-redis-orm", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": "A full functional Redis Orm library written in Typescript.", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -38,2 +38,3 @@ # Redis ORM (Typescript) | ||
RedisOrmSchemaError, | ||
serviceInstance, | ||
} from "ts-redis-orm"; | ||
@@ -192,2 +193,6 @@ | ||
// others | ||
const removeSchemasList = serviceInstance.getRemoveSchemasList("connectionKey"); | ||
const allEntityTypes = serviceInstance.getEntityTypes(); | ||
// errors | ||
@@ -194,0 +199,0 @@ try { |
@@ -9,2 +9,3 @@ import {BaseEntity} from "./BaseEntity"; | ||
import {Query} from "./Query"; | ||
import {serviceInstance} from "./serviceInstance"; | ||
@@ -20,2 +21,3 @@ export { | ||
RedisOrmSchemaError, | ||
serviceInstance, | ||
}; |
@@ -8,3 +8,3 @@ import Debug from "debug"; | ||
import {RedisOrmQueryError} from "./errors/RedisOrmQueryError"; | ||
import {IEntityMeta, IRedisContainer, ISchema} from "./types"; | ||
import {IEntityMeta, IRedisContainer, ISchema, ISchemas} from "./types"; | ||
@@ -45,2 +45,6 @@ const debug = Debug("tsredisorm/default"); | ||
const connection = this.getConnection(target); | ||
return this.getConnectionConfigByConnection(connection); | ||
} | ||
public getConnectionConfigByConnection(connection: string): any { | ||
const configFile = configLoader.getConfigFile(); | ||
@@ -244,5 +248,4 @@ | ||
const redis = await serviceInstance.getRedis(target); | ||
const metaStorageKey = this.getMetaStorageKey(table); | ||
const hashKey = "schemas"; | ||
const remoteSchemasString = await redis.hget(metaStorageKey, hashKey); | ||
const storageKey = this.getSchemasStorageKey(); | ||
const remoteSchemasString = await redis.hget(storageKey, table); | ||
if (remoteSchemasString) { | ||
@@ -271,4 +274,4 @@ return JSON.parse(remoteSchemasString); | ||
public getMetaStorageKey(table: string) { | ||
return `meta:${table}`; | ||
public getSchemasStorageKey() { | ||
return `meta:schemas`; | ||
} | ||
@@ -278,2 +281,26 @@ | ||
// region operations | ||
public getEntityTypes() { | ||
return [...this._entityMetas.keys()]; | ||
} | ||
public async getRemoveSchemasList(connection: string = "default") { | ||
const schemasList: ISchemas = {}; | ||
const connectionConfig = serviceInstance.getConnectionConfigByConnection(connection); | ||
if (connectionConfig) { | ||
const redis = new IORedis(connectionConfig); | ||
const storageKey = serviceInstance.getSchemasStorageKey(); | ||
const result = await redis.hgetall(storageKey); | ||
for (const [table, schemasString] of Object.entries(result)) { | ||
schemasList[table] = JSON.parse(schemasString as string); | ||
} | ||
} | ||
return schemasList; | ||
} | ||
// endregion | ||
// region private methods | ||
@@ -280,0 +307,0 @@ |
@@ -5,2 +5,3 @@ import * as IORedis from "ioredis"; | ||
// decorator | ||
export type ISchemas = {[key: string]: ISchema}; | ||
export interface ISchemaBase { | ||
@@ -74,1 +75,2 @@ primary: boolean; | ||
} | ||
@@ -540,2 +540,15 @@ import {assert, expect } from "chai"; | ||
describe("Service Instance", () => { | ||
it("get entities", async () => { | ||
const entityTypes = serviceInstance.getEntityTypes(); | ||
const entityType = entityTypes.find(x => x === TestingGeneral); | ||
assert.isDefined(entityType); | ||
}); | ||
it("get schemas list", async () => { | ||
const schemasList = await serviceInstance.getRemoveSchemasList(); | ||
assert.hasAllKeys(schemasList, ["testing_general"]); | ||
}); | ||
}); | ||
describe("Clean up", () => { | ||
@@ -542,0 +555,0 @@ it("truncate", async () => { |
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
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
282585
5635
276