-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: subclassing data type in dialects (#145)
* fix: subclassing data type in dialects exports of the abstract data types should not be wrapped with invokable by default, which made subclassing like `class Postgres_DATE extends DataTypes.DATE {}` not working as expected because `DataTypes.DATE` was actually a Proxy instance. This fix defers the invokable wrapping and adds more test cases regarding data types in dialects. * Update test/unit/drivers/postgres/attribute.test.js Co-authored-by: JimmyDaddy <[email protected]> * test: merge test cases Co-authored-by: JimmyDaddy <[email protected]>
- Loading branch information
1 parent
221352c
commit 6e2f51b
Showing
15 changed files
with
146 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert').strict; | ||
const Attribute = require('../../../../src/drivers/mysql/attribute'); | ||
const { BOOLEAN } = Attribute.DataTypes; | ||
|
||
describe('=> Attribute (mysql)', function() { | ||
it('should support TINYINT(1)', async function() { | ||
const attribute= new Attribute('has_image', { | ||
type: BOOLEAN, | ||
defaultValue: false, | ||
}); | ||
assert.equal(attribute.toSqlString(), '`has_image` TINYINT(1) DEFAULT false'); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
test/unit/drivers/mysql.test.js → test/unit/drivers/mysql/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert').strict; | ||
const Attribute = require('../../../../src/drivers/postgres/attribute'); | ||
const { BIGINT, INTEGER, DATE } = Attribute.DataTypes; | ||
|
||
describe('=> Attribute (postgres)', function() { | ||
it('should support BIGSERIAL', async function() { | ||
const attribute= new Attribute('id', { | ||
type: BIGINT, | ||
primaryKey: true, | ||
}); | ||
assert.equal(attribute.toSqlString(), '"id" BIGSERIAL PRIMARY KEY'); | ||
}); | ||
|
||
it('should support SERIAL', async function() { | ||
const attribute= new Attribute('id', { | ||
type: INTEGER, | ||
primaryKey: true, | ||
}); | ||
assert.equal(attribute.toSqlString(), '"id" SERIAL PRIMARY KEY'); | ||
}); | ||
|
||
it('should support WITH TIME ZONE', async function() { | ||
const attribute= new Attribute('createdAt', { | ||
type: DATE, | ||
}); | ||
assert.equal(attribute.toSqlString(), '"created_at" TIMESTAMP WITH TIME ZONE'); | ||
}); | ||
|
||
it('should support WITHOUT TIME ZONE', async function() { | ||
const attribute = new Attribute('createdAt', { | ||
type: DATE(null, false), | ||
}); | ||
assert.equal(attribute.toSqlString(), '"created_at" TIMESTAMP WITHOUT TIME ZONE'); | ||
}); | ||
|
||
it('should support DATE(precision)', async function() { | ||
const attribute= new Attribute('updated_at', { | ||
type: DATE(6), | ||
}); | ||
assert.equal(attribute.toSqlString(), '"updated_at" TIMESTAMP(6) WITH TIME ZONE'); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
test/unit/drivers/postgres.test.js → test/unit/drivers/postgres/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert').strict; | ||
const Attribute = require('../../../../src/drivers/sqlite/attribute'); | ||
const { BIGINT, DATE } = Attribute.DataTypes; | ||
|
||
describe('=> Attribute (sqlite)', function() { | ||
it('should support DATETIME', async function() { | ||
const attribute= new Attribute('createdAt', { | ||
type: DATE, | ||
}); | ||
assert.equal(attribute.toSqlString(), '"created_at" DATETIME'); | ||
}); | ||
|
||
it('should support BIGINT', async function() { | ||
const attribute= new Attribute('id', { | ||
type: BIGINT, | ||
primaryKey: true, | ||
}); | ||
assert.equal(attribute.toSqlString(), '"id" INTEGER PRIMARY KEY'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters