Skip to content

Commit

Permalink
feat: support STRING.BINARY(length), complete unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyDaddy committed Sep 5, 2021
1 parent 2011955 commit b1f1316
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/data_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class DataType {
switch (dataType) {
case 'varchar':
case 'char':
// mysql only
case 'binary':
// mysql only
case 'varbinary':
// postgres only
case 'bytea':
return STRING;
// longtext is only for MySQL
case 'longtext':
Expand Down Expand Up @@ -71,12 +77,12 @@ class STRING extends DataType {
return this;
}

static BINARY() {
return new this().BINARY;
static BINARY(length) {
return new this(length).BINARY;
}

static VARBINARY() {
return new this().VARBINARY;
static VARBINARY(length) {
return new this(length).VARBINARY;
}

toSqlString() {
Expand Down
13 changes: 13 additions & 0 deletions test/unit/data_types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ describe('=> Data Types', () => {
assert.equal(new STRING(127).toSqlString(), 'VARCHAR(127)');
assert.equal(new STRING(255).BINARY.toSqlString(), 'BINARY(255)');
assert.equal(new STRING(255).VARBINARY.toSqlString(), 'VARBINARY(255)');
assert.equal(STRING.BINARY(255).toSqlString(), 'BINARY(255)');
assert.equal(STRING.VARBINARY(255).toSqlString(), 'VARBINARY(255)');
});

it('BOOLEAN', () => {
Expand Down Expand Up @@ -72,6 +74,17 @@ describe('DataTypes.findType()', () => {
it('longtext => TEXT', () => {
assert.equal(DataTypes.findType('longtext'), TEXT);
});

it('binary => STRING', () => {
const { STRING } = DataTypes;
assert.equal(DataTypes.findType('binary'), STRING);
assert.equal(DataTypes.findType('varbinary'), STRING);
});

it('bytea => STRING', () => {
const { STRING } = DataTypes;
assert.equal(DataTypes.findType('bytea'), STRING);
});
});

describe('DataTypes.invokable', function() {
Expand Down

0 comments on commit b1f1316

Please sign in to comment.