Coder Social home page Coder Social logo

better-sqlite3's Introduction

better-sqlite3 Build Status

The fastest and simplest library for SQLite3 in Node.js.

  • Full transaction support
  • Geared for performance, efficiency, and safety
  • Easy-to-use synchronous API (faster than an asynchronous API... yes, you read that correctly)
  • Custom SQL function support
  • 64-bit integer support (invisible until you need it)

How other libraries compare

select 1 row  get()  select 100 rows   all()   select 100 rows iterate() 1-by-1 insert 1 row run() insert 100 rows in a transaction
better-sqlite3 1x 1x 1x 1x 1x
sqlite and sqlite3 8.4x slower 3.7x slower 28.2x slower 3.6x slower 6.0x slower

You can verify these results by running the benchmark yourself. Both npm/sqlite and npm/sqlite3 have nearly identical performance because they both use the same engine.

Installation

npm install --save better-sqlite3

If you have trouble installing, check the troubleshooting guide.

Usage

var Database = require('better-sqlite3');
var db = new Database('foobar.db', options);

var row = db.prepare('SELECT * FROM users WHERE id=?').get(userId);
console.log(row.firstName, row.lastName, row.email);

Why should I use this instead of node-sqlite3?

  • node-sqlite3 uses asynchronous APIs for tasks that are either CPU-bound or serialized. That's not only bad design, but it wastes tons of resources. It also causes mutex thrashing which has devastating effects on performance.
  • node-sqlite3 exposes low-level (C language) memory management functions. better-sqlite3 does it the JavaScript way, allowing the garbage collector to worry about memory management.
  • better-sqlite3 is simpler to use, and it provides nice utilities for some operations that are very difficult or impossible in node-sqlite3.
  • better-sqlite3 is much faster than node-sqlite3 in most cases, and just as fast in all other cases.

Documentation

License

MIT

better-sqlite3's People

Contributors

bengotow avatar carterli avatar joshuawise avatar pdehaan avatar tobbez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.