Skip to content

Commit

Permalink
fix(mariadb): enable bigNumberStrings toggle
Browse files Browse the repository at this point in the history
Closes #578
  • Loading branch information
B4nan committed Aug 9, 2020
1 parent ff7047a commit ee90c64
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/mariadb/src/MariaDbConnection.ts
@@ -1,4 +1,5 @@
import { Connection } from 'mariadb';
import { MySqlConnectionConfig } from 'knex';
import { MySqlConnection } from '@mikro-orm/mysql-base';

// @ts-ignore
Expand All @@ -10,6 +11,13 @@ export class MariaDbConnection extends MySqlConnection {
this.client = this.createKnexClient(this.getPatchedDialect());
}

getConnectionOptions(): MySqlConnectionConfig {
const ret = super.getConnectionOptions();
ret.bigNumberStrings = true;

return ret;
}

private getPatchedDialect() {
Dialect.prototype.driverName = 'mariadb';
Dialect.prototype._driver = () => require('mariadb/callback');
Expand Down
1 change: 1 addition & 0 deletions packages/mysql-base/src/MySqlConnection.ts
Expand Up @@ -27,6 +27,7 @@ export class MySqlConnection extends AbstractSqlConnection {
}

ret.supportBigNumbers = true;
ret.bigNumberStrings = true;

return ret;
}
Expand Down
25 changes: 24 additions & 1 deletion tests/EntityManager.mariadb.test.ts
@@ -1,5 +1,5 @@
import { v4 } from 'uuid';
import { Collection, EntityManager, MikroORM, QueryOrder, Reference, wrap } from '@mikro-orm/core';
import { Collection, Configuration, EntityManager, MikroORM, QueryOrder, Reference, wrap } from '@mikro-orm/core';
import { MariaDbDriver } from '@mikro-orm/mariadb';
import { Author2, Book2, BookTag2, Publisher2, PublisherType } from './entities-sql';
import { initORMMySql, wipeDatabaseMySql } from './bootstrap';
Expand All @@ -19,6 +19,29 @@ describe('EntityManagerMariaDb', () => {
expect(await orm.isConnected()).toBe(true);
});

test('getConnectionOptions()', async () => {
const config = new Configuration({
type: 'mysql',
clientUrl: 'mysql://root@127.0.0.1:3308/db_name',
host: '127.0.0.10',
password: 'secret',
user: 'user',
logger: jest.fn(),
forceUtcTimezone: true,
} as any, false);
const driver = new MariaDbDriver(config);
expect(driver.getConnection().getConnectionOptions()).toEqual({
database: 'db_name',
host: '127.0.0.10',
password: 'secret',
port: 3308,
user: 'user',
timezone: 'Z',
supportBigNumbers: true,
bigNumberStrings: true,
});
});

test('should return mariadb driver', async () => {
const driver = orm.em.getDriver();
expect(driver).toBeInstanceOf(MariaDbDriver);
Expand Down

0 comments on commit ee90c64

Please sign in to comment.