Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"knex.decimal()" creates a column of type float not decimal - tested with sqlite3 and with better-sqlite3 #5789

Open
hassanallaham opened this issue Jan 17, 2024 · 1 comment
Labels

Comments

@hassanallaham
Copy link

hassanallaham commented Jan 17, 2024

Environment

Knex version: 3.1.0
Database + version: Sqlite 3.42.0
Client + version: sqlite3 ^5.1.7 / better-sqlite3 ^9.2.2
OS: Linux Mint 21.3

Bug

Accodrding to the docs (https://knexjs.org/guide/schema-builder.html#decimal) this should create a column of type decimal
but it creates a column of type float not decimal (Tested with sqlite database and with both clients)

Reduced test code:

import knex from 'knex';

const db = knex({
      client: 'sqlite3',
      connection: { filename: '/db.sqlite3' },
      debug: true,
      asyncStackTraces: true,
      log: {
            warn(message) {
                  console.log(`Warning from knex: ${message}`);
            },
            error(message) {
                  console.log(`Error from knex: ${message}`);
            },
            deprecate(message) {
                  console.log(`Deprecate from knex: ${message}`);
            },
            debug(message) {
                  console.log(`Debug from knex stringified: ${JSON.stringify(message)}`);
            },
      },
      migrations: { tableName: 'migrations' },
      useNullAsDefault: true
});

const test = async () => {
      await db.schema.table('testTable', async (table) => {
            table.decimal('newCol', 6, 2);
      });
      return true;
};

test().then(() => {
      console.log('created');
      process.exit(0);
});

and what is shown in terminal:

Debug from knex stringified: [{"sql":"alter table `testTable` add column `newCol` float","bindings":[]}]

created

Notice the Debug result in terminal where you can find it uses "float" and not "decimal"

@rluvaton rluvaton added the bug label Jan 20, 2024
@mohammedbalila
Copy link
Contributor

mohammedbalila commented Apr 6, 2024

Hey @rluvaton
I found that in sqlit3 column compiler double, decimal, and floating are all converted to float.
I think sqlite3 supports all three types, I can change that and create a PR. But is there a reason for this behaviour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants