mirror of
https://github.com/knex/knex.git
synced 2025-09-17 04:03:36 +00:00
Add integration test for specifictype (#4211)
This commit is contained in:
parent
41606d799c
commit
bf287be13a
@ -106,6 +106,11 @@ class ColumnCompiler {
|
||||
return `decimal(${this._num(precision, 8)}, ${this._num(scale, 2)})`;
|
||||
}
|
||||
|
||||
// Used to support custom types
|
||||
specifictype(type) {
|
||||
return type;
|
||||
}
|
||||
|
||||
// Modifiers
|
||||
// -------
|
||||
|
||||
@ -154,7 +159,6 @@ ColumnCompiler.prototype.timestamp = 'timestamp';
|
||||
ColumnCompiler.prototype.enu = 'varchar';
|
||||
ColumnCompiler.prototype.bit = ColumnCompiler.prototype.json = 'text';
|
||||
ColumnCompiler.prototype.uuid = 'char(36)';
|
||||
ColumnCompiler.prototype.specifictype = (type) => type;
|
||||
ColumnCompiler.prototype.increments =
|
||||
'integer not null primary key autoincrement';
|
||||
ColumnCompiler.prototype.bigincrements =
|
||||
|
57
test/integration2/schema/custom-type.spec.js
Normal file
57
test/integration2/schema/custom-type.spec.js
Normal file
@ -0,0 +1,57 @@
|
||||
const { expect } = require('chai');
|
||||
const { getAllDbs, getKnexForDb } = require('../util/knex-instance-provider');
|
||||
|
||||
describe('Schema', () => {
|
||||
describe('customType', () => {
|
||||
getAllDbs().forEach((db) => {
|
||||
describe(db, () => {
|
||||
let knex;
|
||||
const tblName = 'table_with_custom_varchar1';
|
||||
const colName = 'varchar_col1';
|
||||
|
||||
before(async () => {
|
||||
knex = getKnexForDb(db);
|
||||
await knex.schema.dropTableIfExists(tblName);
|
||||
await knex.schema.createTable(tblName, (table) => {
|
||||
table.specificType(colName, 'varchar(42)');
|
||||
});
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await knex.schema.dropTable(tblName);
|
||||
return knex.destroy();
|
||||
});
|
||||
|
||||
it('Allows to specify custom type params', async () => {
|
||||
let res;
|
||||
switch (db) {
|
||||
case 'sqlite3':
|
||||
res = await knex.schema.raw(`PRAGMA table_info(${tblName})`);
|
||||
expect(res.find((c) => c.name === colName).type).to.equal(
|
||||
'varchar(42)'
|
||||
);
|
||||
break;
|
||||
case 'postgres':
|
||||
res = await knex
|
||||
.select(['data_type', 'character_maximum_length'])
|
||||
.from('information_schema.columns')
|
||||
.where({ table_name: tblName, column_name: colName });
|
||||
expect(res[0].data_type).to.equal('character varying');
|
||||
expect(res[0].character_maximum_length).to.equal(42);
|
||||
break;
|
||||
case 'mssql':
|
||||
case 'mysql':
|
||||
case 'mysql2':
|
||||
res = await knex
|
||||
.select(['DATA_TYPE', 'CHARACTER_MAXIMUM_LENGTH'])
|
||||
.from('INFORMATION_SCHEMA.COLUMNS')
|
||||
.where({ table_name: tblName, column_name: colName });
|
||||
expect(res[0].DATA_TYPE).to.equal('varchar');
|
||||
expect(res[0].CHARACTER_MAXIMUM_LENGTH).to.equal(42);
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user