feat: uuid field
This commit is contained in:
parent
e6f71c65fd
commit
2c0d3fcc5a
@ -0,0 +1,30 @@
|
||||
import { mockDatabase } from '../';
|
||||
import { Database } from '../../database';
|
||||
|
||||
describe('string field', () => {
|
||||
let db: Database;
|
||||
|
||||
beforeEach(async () => {
|
||||
db = mockDatabase();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
it('define', async () => {
|
||||
const Test = db.collection({
|
||||
name: 'tests',
|
||||
autoGenId: false,
|
||||
fields: [
|
||||
{
|
||||
type: 'uuid',
|
||||
name: 'id',
|
||||
primaryKey: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
await Test.sync();
|
||||
await Test.model.create();
|
||||
});
|
||||
});
|
@ -22,6 +22,7 @@ import { StringFieldOptions } from './string-field';
|
||||
import { TextFieldOptions } from './text-field';
|
||||
import { TimeFieldOptions } from './time-field';
|
||||
import { UidFieldOptions } from './uid-field';
|
||||
import { UUIDFieldOptions } from './uuid-field';
|
||||
import { VirtualFieldOptions } from './virtual-field';
|
||||
|
||||
export * from './array-field';
|
||||
@ -43,6 +44,7 @@ export * from './string-field';
|
||||
export * from './text-field';
|
||||
export * from './time-field';
|
||||
export * from './uid-field';
|
||||
export * from './uuid-field';
|
||||
export * from './virtual-field';
|
||||
|
||||
export type FieldOptions =
|
||||
@ -64,6 +66,7 @@ export type FieldOptions =
|
||||
| TimeFieldOptions
|
||||
| DateFieldOptions
|
||||
| UidFieldOptions
|
||||
| UUIDFieldOptions
|
||||
| PasswordFieldOptions
|
||||
| ContextFieldOptions
|
||||
| BelongsToFieldOptions
|
||||
|
21
packages/core/database/src/fields/uuid-field.ts
Normal file
21
packages/core/database/src/fields/uuid-field.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { BaseColumnFieldOptions, Field, FieldContext } from './field';
|
||||
|
||||
export class UuidField extends Field {
|
||||
constructor(options?: any, context?: FieldContext) {
|
||||
super(
|
||||
{
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
...options,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
get dataType() {
|
||||
return DataTypes.UUID;
|
||||
}
|
||||
}
|
||||
|
||||
export interface UUIDFieldOptions extends BaseColumnFieldOptions {
|
||||
type: 'uuid';
|
||||
}
|
Loading…
Reference in New Issue
Block a user