mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-11-30 03:08:31 +08:00
feat(database): improve text field
This commit is contained in:
parent
65b1e7c5a5
commit
c26e43a34f
@ -0,0 +1,47 @@
|
||||
import { mockDatabase } from '../';
|
||||
import { Database } from '../../database';
|
||||
|
||||
describe('text field', () => {
|
||||
let db: Database;
|
||||
|
||||
beforeEach(async () => {
|
||||
db = mockDatabase();
|
||||
await db.clean({ drop: true });
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
it('should create text field type', async () => {
|
||||
const Test = db.collection({
|
||||
name: 'tests',
|
||||
fields: [
|
||||
{
|
||||
type: 'text',
|
||||
name: 'text1',
|
||||
defaultValue: 'a',
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
name: 'text2',
|
||||
length: 'tiny',
|
||||
defaultValue: 'a',
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
name: 'text3',
|
||||
length: 'medium',
|
||||
defaultValue: 'a',
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
name: 'text4',
|
||||
length: 'long',
|
||||
defaultValue: 'a',
|
||||
},
|
||||
],
|
||||
});
|
||||
await Test.sync();
|
||||
});
|
||||
});
|
@ -3,10 +3,20 @@ import { BaseColumnFieldOptions, Field } from './field';
|
||||
|
||||
export class TextField extends Field {
|
||||
get dataType() {
|
||||
if (this.database.inDialect('mysql', 'mariadb') && this.options.length) {
|
||||
return DataTypes.TEXT(this.options.length);
|
||||
}
|
||||
return DataTypes.TEXT;
|
||||
}
|
||||
|
||||
init() {
|
||||
if (this.database.inDialect('mysql', 'mariadb')) {
|
||||
this.options.defaultValue = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface TextFieldOptions extends BaseColumnFieldOptions {
|
||||
type: 'text';
|
||||
length?: 'tiny' | 'medium' | 'long';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user