Comparing version 1.1.0 to 1.1.1
@@ -10,3 +10,3 @@ import { Type } from './metadata/type'; | ||
constructor(metadata: Metadata, client: redis.RedisClient); | ||
commit<T>(entity: T): Promise<void>; | ||
save<T>(entity: T): Promise<void>; | ||
count<T>(entityType: Type<T>): Promise<number>; | ||
@@ -13,0 +13,0 @@ list<T>(entityType: Type<T>, limit?: number, offset?: number, orderBy?: OrderBy): Promise<T[]>; |
@@ -20,3 +20,3 @@ "use strict"; | ||
} | ||
commit(entity) { | ||
save(entity) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -81,3 +81,3 @@ const { name, uniques, primary, canBeListed, indexes, properties } = this.metadata.getEntityMetadataFromInstance(entity); | ||
if (canBeListed) { | ||
yield this.client.saddAsync(this.getListKeyName(name), entity[primary]); | ||
yield this.client.rpushAsync(this.getListKeyName(name), entity[primary]); | ||
} | ||
@@ -89,3 +89,5 @@ return null; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (yield this.listIds(entityType)).length; | ||
const { name } = this.metadata.getEntityMetadataFromType(entityType); | ||
const keyName = this.getListKeyName(name); | ||
return yield this.client.llenAsync(keyName); | ||
}); | ||
@@ -127,4 +129,5 @@ } | ||
const response = []; | ||
for (const id of ids) { | ||
response.push(yield this.getOne(entityType, id)); | ||
const numberOfResult = (ids.length < limit) ? ids.length : limit; | ||
for (let index = 0; index < numberOfResult; index++) { | ||
response.push(yield this.getOne(entityType, ids[index])); | ||
} | ||
@@ -178,12 +181,12 @@ return response; | ||
const keyName = this.getListKeyName(name); | ||
let start = 0; | ||
let stop = -1; | ||
if (offset !== undefined) { | ||
start = offset; | ||
} | ||
if (limit !== undefined) { | ||
stop = start + limit - 1; | ||
} | ||
if (orderBy !== undefined) { | ||
const sortableKey = this.getSortableKeyName(name, orderBy.field); | ||
let start = 0; | ||
let stop = -1; | ||
if (offset !== undefined) { | ||
start = offset; | ||
} | ||
if (limit !== undefined) { | ||
stop = start + limit - 1; | ||
} | ||
if (orderBy.strategy === 'ASC') { | ||
@@ -196,9 +199,3 @@ return yield this.client.zrangeAsync(sortableKey, start, stop); | ||
} | ||
if (limit !== undefined || offset !== undefined) { | ||
if (limit === undefined || offset === undefined) { | ||
throw new Error('You must specify limit and offset, not just one arg.'); | ||
} | ||
return yield this.client.sortAsync(keyName, 'ALPHA', 'LIMIT', limit, offset); | ||
} | ||
return yield this.client.smembersAsync(keyName); | ||
return yield this.client.lrangeAsync(keyName, start, stop); | ||
}); | ||
@@ -218,3 +215,3 @@ } | ||
if (canBeListed) { | ||
yield this.client.sremAsync(this.getListKeyName(name), id); | ||
yield this.client.lremAsync(this.getListKeyName(name), 1, id); | ||
} | ||
@@ -221,0 +218,0 @@ yield this.dropSortables(persistedEntity); |
{ | ||
"name": "redisk", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "TypeScript ORM for Redis.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -77,3 +77,3 @@ Redisk | ||
```ts | ||
await redisk.commit<User>(new User(id, name, email, color, created)); | ||
await redisk.save<User>(new User(id, name, email, color, created)); | ||
``` | ||
@@ -80,0 +80,0 @@ |
@@ -23,3 +23,3 @@ import { Type } from './metadata/type'; | ||
async commit<T>(entity: T): Promise<void> { | ||
async save<T>(entity: T): Promise<void> { | ||
@@ -110,3 +110,3 @@ const {name, uniques, primary, canBeListed, indexes, properties} = this.metadata.getEntityMetadataFromInstance(entity); | ||
if (canBeListed) { | ||
await this.client.saddAsync(this.getListKeyName(name), entity[primary]); | ||
await this.client.rpushAsync(this.getListKeyName(name), entity[primary]); | ||
} | ||
@@ -118,3 +118,6 @@ | ||
async count<T>(entityType: Type<T>): Promise<number> { | ||
return (await this.listIds(entityType)).length; | ||
const { name } = this.metadata.getEntityMetadataFromType(entityType); | ||
const keyName = this.getListKeyName(name); | ||
return await this.client.llenAsync(keyName); | ||
} | ||
@@ -163,4 +166,5 @@ | ||
for (const id of ids) { | ||
response.push(await this.getOne(entityType, id)); | ||
const numberOfResult = (ids.length < limit) ? ids.length : limit; | ||
for (let index = 0; index < numberOfResult; index++) { | ||
response.push(await this.getOne(entityType, ids[index])); | ||
} | ||
@@ -227,15 +231,17 @@ | ||
let start = 0; | ||
let stop = -1; | ||
if (offset !== undefined) { | ||
start = offset; | ||
} | ||
if (limit !== undefined) { | ||
stop = start + limit - 1; | ||
} | ||
if (orderBy !== undefined) { | ||
const sortableKey = this.getSortableKeyName(name, orderBy.field); | ||
let start = 0; | ||
let stop = -1; | ||
if (offset !== undefined) { | ||
start = offset; | ||
} | ||
if (limit !== undefined) { | ||
stop = start + limit - 1; | ||
} | ||
if (orderBy.strategy === 'ASC') { | ||
@@ -248,10 +254,3 @@ return await this.client.zrangeAsync(sortableKey, start, stop); | ||
if (limit !== undefined || offset !== undefined) { | ||
if (limit === undefined || offset === undefined) { | ||
throw new Error('You must specify limit and offset, not just one arg.'); | ||
} | ||
return await this.client.sortAsync(keyName, 'ALPHA', 'LIMIT', limit, offset); | ||
} | ||
return await this.client.smembersAsync(keyName); | ||
return await this.client.lrangeAsync(keyName, start, stop); | ||
} | ||
@@ -272,3 +271,3 @@ | ||
if (canBeListed) { | ||
await this.client.sremAsync(this.getListKeyName(name), id); | ||
await this.client.lremAsync(this.getListKeyName(name), 1, id); | ||
} | ||
@@ -275,0 +274,0 @@ |
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
57920
63
1372