Skip to content
This repository was archived by the owner on Jul 1, 2026. It is now read-only.
This repository was archived by the owner on Jul 1, 2026. It is now read-only.

BigInt support #1058

Open
Open

Description

@wmertens

Initial

Currently, BigInts (Node 10.7+) are converted to null when storing:

> s=require('sqlite3')
> d=new s.Database(':memory:')
Database { open: false, filename: ':memory:', mode: 65542 }
> d.exec('create table t(s blob)')
Database { open: true, filename: ':memory:', mode: 65542 }

> d.run('insert into t values(?)',[1234n], ()=>d.all('select * from t',console.log))
Database { open: true, filename: ':memory:', mode: 65542 }
> null [ { s: null } ]

> d.run('insert into t values(?)',[1234], ()=>d.all('select * from t',console.log))
Database { open: true, filename: ':memory:', mode: 65542 }
> null [ { s: null }, { s: 1234 } ]

Since signed 64 bit ints are a native datatype for SQLite, I propose that BigInts that fit in a 64 bit int are stored as ints, and all the rest is stored as a BLOB.

Here's some N-API code that converts BigInt to Buffer: https://github.com/no2chem/bigint-buffer

Complications

Not sure what should happen when reading integers, since BigInts and Numbers are not easy to mix in JS. Most likely sqlite3 would need a flag to allow reading integers as bigint, but even then you'd want to decide on a column-by-column basis which one is read as a bigint.

Activity

  1. sacOO7 commented on May 30, 2021

    @sacOO7

    Referencing on the comment, please check #922 (comment)

    To install use
    npm i https://github.com/sacOO7/node-sqlite3
    or
    yarn add https://github.com/sacOO7/node-sqlite3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions