npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@comdec_/node_sqlite3

v1.1.1

Published

A small node package to create basic sqlite binding for nodeJS using python

Downloads

6

Readme

Node SQLite3

Summary

Introduction

Node SQLite is a small NodeJS package to create simple SQLite3 bindings using the pyhton standard libray.
It allow you to run easly SQL queries and mutation with one single async function. Like so :

const sqlite = require("node_sqlite3");

const connection = new sqlite.Connection("path/to/db/file");
const { rows } = await connection.runSql("SELECT * FROM mytable WHERE test > 1");

Requirement

Installation

npm i @comdec_/node_sqlite3
# You can either install the package with npm or yarn
yarn add @comdec_/node_sqlite3

Then import the module at the top of your file :

const sqlite = require("@comdec_/node_sqlite3");

QuickStart

Connecting

You can connect to your databae simply by importing the package and instantiating the connection :

const sqlite = require("@comdec_/node_sqlite3");

const connection = new sqlite.Connection("path/to/db/file");

Running SQL

Then, using this connection, you can run queries and mutations using the runSql function :

const { rows } = await connection.runSql("SELECT * FROM mytable WHERE test > 1");

This function is async and takes as parameter a string, witch represents your query or your mutation. It will return a Promise witch contain a QueryResponse.

The response can either contain an error, nothing or an Array of rows, witch you can access with the rows attribute of QueryResponse.

Adding arguments

You can aslo add argument to your query/mutation. To do so, simply add an array with these arguments, the function will automatically replace each "?" with the corresponding index argument :

// This is equal to run this : INSERT INTO users(name, email, phone) VALUES ("John Doe", "[email protected]", "+33 6 12 34 56 78");
await connection.runSql(
  "INSERT INTO users(name, email, phone) VALUES (?, ?, ?);", 
  ["John Doe", "[email protected]", "+33 6 12 34 56 78"]
);

Running multiple queries

Running the same query or mutation multiple times with differents armuments is sometimes boring, but you can use the Connection#runMany method to be more efficient :

// This is equal to run this : INSERT INTO users(name, email, phone) VALUES ("John Doe", "[email protected]", "+33 6 12 34 56 78");
await connection.runMany(
  "INSERT INTO users(name, id) VALUES (?, ?);", 
  [
    ["John Doe", 1],
    ["John Doe", 2],
    ["John Doe", 3]
  ]
);

console.log((await connection.runSql("SELECT * FROM users")).toString());
// .---------------.
// |   name   | id |
// |----------|----|
// | John Doe |  1 |
// | John Doe |  2 |
// | John Doe |  3 |
// '---------------'

The method return an array witch contain all of the QueryResponse of each SQL mutation/query.

Running SQL files

You can also run entire SQL files : index.js :

await connection.runSql("CREATE TABLE IF NOT EXISTS users (name VARCHAR(40), id INT);")
await connection.runFile('./test.sql');
  
console.log((await connection.runSql("SELECT * FROM users")).toString());

test.sql :

INSERT INTO users(name, id) VALUES ("John Doe", 3);

INSERT INTO users(name, id) VALUES ("John Doe", 4);

INSERT INTO users(name, id) VALUES (
  "John Doe", 5
);

This will print

.---------------.
|   name   | id |
|----------|----|
| John Doe |  3 |
| John Doe |  4 |
| John Doe |  5 |
'---------------'

The method takes as argument the file path (relative or absolute) witch represents the location of the file you want to execute and return an array witch contain all of the QueryResponse of each SQL mutation/query.

Contribution and issues

If you encounter an issue or want to ask for a feature, feel free to create an issue

If you want to contribute, you can create some pull requests to fix issues, all the help is welcome !

Contributors