Skip to content

Commit 23a1b0c

Browse files
committed
fix: return enum type
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent 9045ad8 commit 23a1b0c

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

lib/discovery.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ function mixinDiscovery(MySQL, mysql) {
340340
case 'MEDIUMTEXT':
341341
case 'LONGTEXT':
342342
case 'TEXT':
343-
case 'ENUM':
344343
case 'SET':
345344
return 'String';
346345
case 'TINYBLOB':
@@ -380,6 +379,8 @@ function mixinDiscovery(MySQL, mysql) {
380379
case 'BOOL':
381380
case 'BOOLEAN':
382381
return 'Boolean';
382+
case 'ENUM':
383+
return columnType;
383384
default:
384385
return 'String';
385386
}

test/mysql.discover.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ describe('Discover LDL schema from a table', function() {
257257
});
258258
});
259259

260+
describe('Discover and handle enum', function() {
261+
let schema;
262+
before(function(done) {
263+
db.discoverSchema('PATIENT', {owner: 'STRONGLOOP'}, function(err, schema_) {
264+
schema = schema_;
265+
done(err);
266+
});
267+
});
268+
it('should validate enum type for PATIENT', function() {
269+
assert.ok(/STRONGLOOP/i.test(schema.options.mysql.schema));
270+
assert.strictEqual(schema.options.mysql.table, 'PATIENT');
271+
assert.strictEqual(schema.name, 'Patient');
272+
assert.strictEqual(schema.properties.type.type, "enum('INPATIENT','OUTPATIENT')");
273+
});
274+
});
275+
260276
describe('Discover and build models', function() {
261277
let models;
262278
before(function(done) {

test/schema.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ LOCK TABLES `CUSTOMER` WRITE;
4949
/*!40000 ALTER TABLE `CUSTOMER` ENABLE KEYS */;
5050
UNLOCK TABLES;
5151

52+
53+
--
54+
-- Table structure for table `INVENTORY`
55+
--
56+
57+
DROP TABLE IF EXISTS `PATIENT`;
58+
/*!40101 SET @saved_cs_client = @@character_set_client */;
59+
/*!40101 SET character_set_client = utf8 */;
60+
CREATE TABLE `PATIENT` (
61+
`ID` varchar(20) NOT NULL,
62+
`NAME` varchar(20) NOT NULL,
63+
`TYPE` ENUM('INPATIENT', 'OUTPATIENT') DEFAULT NULL,
64+
PRIMARY KEY (`ID`)
65+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
66+
/*!40101 SET character_set_client = @saved_cs_client */;
67+
68+
5269
--
5370
-- Table structure for table `INVENTORY`
5471
--

0 commit comments

Comments
 (0)