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

aa-sqlite

v1.0.29

Published

A simple way to interact with sqlite3 databases synchronzously.

Downloads

174

Readme

Async-Await-SQLITE

Purpose

SQLite is popular embedded database engine used in mobile devices and computers. Although powerfull and lightweight, its asynchronous nature can be a stumbling block for beginners.

AA-SQLite is a promise based SQLite wrapper that allows applications to interact with SQLite3 databases synchronously. When using AA-SQLite to query a database, application execution is paused until the result of the query has been resolved. AA-SQlite supports foreign key integration, and the following database operations:

  1. Select
  2. Delete
  3. Insert
  4. Update

IMPORTANT LINKS

  • Link to github repository
  • [Alternative Implementation] (https://www.scriptol.com/sql/sqlite-async-await.php)
  • [SQLite Tutorials] (https://www.sqlitetutorial.net/sqlite-nodejs/)

Technologies Used

  • SQLite
  • Node.js with Async/Await

Setup

In order to use this package, you will need to create a SQLite3 project, by installing the following required technologies.

Required Technologies

  1. Node.js LTS
  2. NPM
  3. Git & Git Bash
  4. SQLite

Installation and Configuration

  1. Install all required technologies
  2. [Optional] Enable SQLite foreign key constraint:
    1. Open the command prompt
    2. Type "sqlite3" [ENTER], to enter the SQLITE prompt
    3. Type "PRAGMA foreign_keys = ON;" [ENTER]
    4. Click "CTRL+C" [ENTER], to exit SQLite prompt
  3. Create a new project in your editor of choice
  4. Install the AA-SQLite package
    1. npm i aa-sqlite --save
  5. See instructions on database creation.

Create a Sample Database

  1. Create a database.js file
    1. Require the sqlite3 package
      • const sqlite3 = require('sqlite3').verbose();
    2. Set the location of your database file.
      • const DBSOURCE = "./geo_db.sqlite";
    3. Open a database connection, create a table, and populate the table:
      let db = new sqlite3.Database(DBSOURCE, (err) => {
          if (err) {
              console.error("DB Error", err);
              return;
          } else { 
              console.log('Connected to the SQLite geo_db database.');
              db.run(`CREATE TABLE geo_table(
                  id INTEGER,
                  latitude DECIMAL(5, 2), 
                  longitude DECIMAL(5, 2), 
                  city TEXT, 
                  state TEXT,
                  PRIMARY KEY(id)
              )`,
                  (err) => {
                      if (err) {
                          console.log("geo_table NOT created", err);
                      } else {
                          console.log("geo_table created");
                          var insert = 'INSERT INTO geo_table (lat, lon, city, state) 
                              VALUES (?, ?, ?, ?)';
                          db.run(insert, [33.75, 84.39, "Atlanta", "Georgia"]);
                          db.run(insert, [34.05, 118.24, "Los Angeles", "California"]);
                          console.log("geo_table populated");
                      }
                  });
          }//db created
      });
    4. Close the database connection
      db.close((err) => {
          if (err) {
              console.error(err.message);
          }
          console.log('geo_db connection is closed.');
      });
    5. Run the javascript file
      • At a command prompt, change the directory to the location of the database.js file.
      • Type: "node database.js" [Enter]

Query the Database with AA-SQLite

  1. Prerequisites:
    1. Set the location of your database file.
      • const DBSOURCE = "./database_name.sqlite";
    2. Require the AA-SQLite package
      • const aaSqlite = require("aa-sqlite");
  2. Open the database connection:
    1. Syntax:
      • await aaSqlite.open(DBSOURCE: string, Enable_Foreign_Key: boolean)
  3. Query the database:
    1. [SELECT Query - Syntax1] : Used to return a single unique value, such as a key.
      • await aaSqlite.get(query: string, values: array);
    2. [SELECT Query - Syntax2] : Used to return all matching records.
      • await aaSqlite.get_all(query: string, values: array);
    3. [INSERT, UPDATE, or DELETE Query - Syntax] : Used for queries that do not return a value.
      • await aaSqlite.push(query: string, values: array);
    4. Parameters:
      1. query: Any of the sqlite3 query strings mentioned above.
      2. values: Array containing the actual values to be inserted in an INSERT INTO VALUES clause. If the values are contained in the query, or the query does not require them, this parameter should be provided an empty array [].
  4. Close the database:
    1. Syntax:
      • aaSqlite.close();

Use

  1. This repo is available for public non-commercial use only.