redisk
Advanced tools
Comparing version 2.1.6 to 2.1.7
@@ -5,2 +5,3 @@ import 'reflect-metadata'; | ||
indexed?: boolean; | ||
defaultValue?: any; | ||
}): Function; |
@@ -23,2 +23,3 @@ "use strict"; | ||
type, | ||
defaultValue: options.defaultValue, | ||
}; | ||
@@ -25,0 +26,0 @@ }; |
@@ -6,2 +6,3 @@ export interface PropertyMetadata { | ||
indexed: boolean; | ||
defaultValue: any; | ||
} |
@@ -330,2 +330,5 @@ "use strict"; | ||
let convertedValue = value; | ||
if ((value === 'undefined' || value === null) && property.defaultValue !== undefined) { | ||
return property.defaultValue; | ||
} | ||
switch (property.type) { | ||
@@ -332,0 +335,0 @@ case 'Boolean': |
{ | ||
"name": "redisk", | ||
"version": "2.1.6", | ||
"version": "2.1.7", | ||
"description": "TypeScript ORM for Redis.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -170,2 +170,4 @@ <h1 align="center"> | ||
You can also set a default value. | ||
Both options are false by default. | ||
@@ -177,3 +179,3 @@ | ||
@Property({indexed: true, searchable: false}) | ||
@Property({indexed: true, searchable: false, defaultValue: 'foo'}) | ||
public readonly created: Date; | ||
@@ -180,0 +182,0 @@ |
@@ -19,3 +19,3 @@ import { Entity } from '../../src/decorators/entity.decorator'; | ||
@Property() | ||
@Property({defaultValue: 'Empty'}) | ||
public readonly description: string; | ||
@@ -22,0 +22,0 @@ |
@@ -50,2 +50,14 @@ import { RediskTestUtils } from './utils/redisk-test-utils'; | ||
describe('Get one with a default value', () => { | ||
it('should return the setted default value if is undefined', async () => { | ||
const id = '::defaultvalueid::'; | ||
const created = new Date(); | ||
const user = new User(id, 'Enver', null, 'enver@me.com', null, null, null, created); | ||
await utils.redisk.save(user); | ||
expect((await utils.redisk.getOne(User, id)).description).toEqual('Empty'); | ||
}); | ||
}); | ||
describe('Get one by a key that is not unique', () => { | ||
@@ -52,0 +64,0 @@ it('should throw error', async () => { |
171414
2023
399