Skip to content

Commit

Permalink
Updated sqlite3 and better-sqlite3 to use more accurate numeric types
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammedbalila committed Apr 22, 2024
1 parent 9659a20 commit fdd5f29
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
7 changes: 3 additions & 4 deletions lib/dialects/sqlite3/schema/sqlite-columncompiler.js
Expand Up @@ -37,10 +37,9 @@ class ColumnCompiler_SQLite3 extends ColumnCompiler {

ColumnCompiler_SQLite3.prototype.json = 'json';
ColumnCompiler_SQLite3.prototype.jsonb = 'json';
ColumnCompiler_SQLite3.prototype.double =
ColumnCompiler_SQLite3.prototype.decimal =
ColumnCompiler_SQLite3.prototype.floating =
'float';
ColumnCompiler_SQLite3.prototype.double = 'double'
ColumnCompiler_SQLite3.prototype.decimal = 'decimal'
ColumnCompiler_SQLite3.prototype.floating = 'float';
ColumnCompiler_SQLite3.prototype.timestamp = 'datetime';
// autoincrement without primary key is a syntax error in SQLite, so it's necessary
ColumnCompiler_SQLite3.prototype.increments =
Expand Down
19 changes: 16 additions & 3 deletions test/unit/schema-builder/better-sqlite3.js
Expand Up @@ -755,6 +755,7 @@ describe('BetterSQLite3 SchemaBuilder', function () {
equal(tableSql[0].sql, 'alter table `users` add column `foo` float');
});


it('adding double', function () {
tableSql = client
.schemaBuilder()
Expand All @@ -764,7 +765,19 @@ describe('BetterSQLite3 SchemaBuilder', function () {
.toSQL();

equal(1, tableSql.length);
equal(tableSql[0].sql, 'alter table `users` add column `foo` float');
equal(tableSql[0].sql, 'alter table `users` add column `foo` double');
});

it('adding double, no precision', function () {
tableSql = client
.schemaBuilder()
.table('users', function (table) {
table.double('foo', null);
})
.toSQL();

equal(1, tableSql.length);
equal(tableSql[0].sql, 'alter table `users` add column `foo` double');
});

it('adding decimal', function () {
Expand All @@ -776,7 +789,7 @@ describe('BetterSQLite3 SchemaBuilder', function () {
.toSQL();

equal(1, tableSql.length);
equal(tableSql[0].sql, 'alter table `users` add column `foo` float');
equal(tableSql[0].sql, 'alter table `users` add column `foo` decimal');
});

it('test adding decimal, no precision', function () {
Expand All @@ -788,7 +801,7 @@ describe('BetterSQLite3 SchemaBuilder', function () {
.toSQL();

equal(1, tableSql.length);
equal(tableSql[0].sql, 'alter table `users` add column `foo` float');
equal(tableSql[0].sql, 'alter table `users` add column `foo` decimal');
});

it('adding boolean', function () {
Expand Down
18 changes: 15 additions & 3 deletions test/unit/schema-builder/sqlite3.js
Expand Up @@ -815,7 +815,19 @@ describe('SQLite SchemaBuilder', function () {
.toSQL();

equal(1, tableSql.length);
equal(tableSql[0].sql, 'alter table `users` add column `foo` float');
equal(tableSql[0].sql, 'alter table `users` add column `foo` double');
});

it('adding double, no precision', function () {
tableSql = client
.schemaBuilder()
.table('users', function (table) {
table.double('foo', null);
})
.toSQL();

equal(1, tableSql.length);
equal(tableSql[0].sql, 'alter table `users` add column `foo` double');
});

it('adding decimal', function () {
Expand All @@ -827,7 +839,7 @@ describe('SQLite SchemaBuilder', function () {
.toSQL();

equal(1, tableSql.length);
equal(tableSql[0].sql, 'alter table `users` add column `foo` float');
equal(tableSql[0].sql, 'alter table `users` add column `foo` decimal');
});

it('test adding decimal, no precision', function () {
Expand All @@ -839,7 +851,7 @@ describe('SQLite SchemaBuilder', function () {
.toSQL();

equal(1, tableSql.length);
equal(tableSql[0].sql, 'alter table `users` add column `foo` float');
equal(tableSql[0].sql, 'alter table `users` add column `foo` decimal');
});

it('adding boolean', function () {
Expand Down

0 comments on commit fdd5f29

Please sign in to comment.