Skip to content

Commit

Permalink
fix: realm.DataTypes should be invokable (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjake authored Feb 24, 2022
1 parent c0e695e commit b9b727e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const connect = async function connect(opts) {
return realm;
};

Object.assign(Realm.prototype, migrations);
Object.assign(Realm.prototype, migrations, { DataTypes });
Object.assign(Realm, {
connect,
Bone,
Expand Down
5 changes: 0 additions & 5 deletions src/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ class Realm {
this.options = Spine.options = options;
}

get DataTypes() {
if (!this.driver) throw new Error('database not connected yet');
return this.driver.DataTypes;
}

define(name, attributes, opts = {}, descriptors = {}) {
const Model = class extends this.Bone {
static name = name;
Expand Down
18 changes: 18 additions & 0 deletions test/unit/realm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1021,4 +1021,22 @@ describe('=> Realm', () => {
assert.equal(Post.attributes.deletedAt.columnName, 'gmt_deleted');
});
});

describe('realm.DataTypes', function() {
it('DataTypes should be invokable', async function() {
const realm = new Realm({
port: process.env.MYSQL_PORT,
user: 'root',
database: 'leoric',
});
await realm.connect();
assert.equal(realm.DataTypes, DataTypes);
const { STRING } = realm.DataTypes;
const Note = realm.define('Note', {
name: { type: STRING(255) },
});
await Note.sync({ force: true });
await Note.create({ name: 'Link' });
});
});
});

0 comments on commit b9b727e

Please sign in to comment.