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

promised-websql

v0.1.1

Published

![npm](https://img.shields.io/npm/v/promised-websql) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/promised-websql) # Promised WebSQL

Downloads

7

Readme

npm npm bundle size

Promised WebSQL

A lightweight wrapper for WebSQL implementations to make them support promises.

Tested with:

  • Chrome's WebSQL
  • Expo SDK's expo-sqlite
  • React Native's react-native-sqlite-storage

While not tested, it should work with Cordova's cordova-sqlite-storage and any WebSQL implementation in accordance with this standard.

Why

I know WebSQL is deprecated and will not be developed, but it is still used widely and remains the only SQL option on React Native/Cordova projects. I had to use SQL in one and wanted to write it with promises, that is why I created this package.

Installation

npm install promised-websql --save or yarn add promised-websql.

Usage

import * as SQLite from 'expo-sqlite';
import PromisedWebSQL from 'promised-websql';

// Setup
const db = SQLite.openDatabase('test.db');
const promised_db = PromisedWebSQL(db);

// Usage
promised_db.sql(
  'CREATE TABLE AWESOME_PACKAGES(' +
  'ID INT PRIMARY KEY NOT NULL, ' +
  'NAME TEXT NOT NULL, ' +
  'URL TEXT NOT NULL);')
  .then(([transaction, result]) => {
    console.log('Table created!');
  })
  .catch((error) => {
    console.error(error);
  });

API Reference

####PromisedWebSQL(db)

  • Arguments:
    • db: object - a DB-like object that conforms to the WebSQL specification, most notably, has a #transaction function.
  • Returns:
    • {sql: function, sqls: function} - an object that exposes the api, listed below

####PromisedWebSQL#sql(sql_query, paramerters?)

Execute an SQL query on the database, optionally interpolate with parameters.

  • Arguments:
    • sql_query: string - an SQL query to execute
    • parameters?: Array<string> - an optional array of parameters to interpolate ? symbols in sql_query.
  • Returns:
    • Promise<[transaction: SQLTransaction, result: ResultSet]> - A promise which resolves when the transaction is executed. Resolves with an array, where the first element is the transaction itself and the second is the response from the database api. If rejected, rejects with an array where the first element is the transaction itself, and the second is the error returned from the database api.

####PromisedWebSQL#sqls(sql_queries)

Execute multiple SQL queries on the database, optionally interpolate with parameters.

  • Arguments:
    • sql_queries: Array<Array<string>> - an array of arrays. Each array represents an SQL query, where the first string is the SQL query itself, the rest is parameters, if there are any.
  • Returns:
    • Promise<Array<[transaction: SQLTransaction, result: ResultSet]>> - A promise which resolves when all the transactions are executed. Resolves with an array of arrays, where each array represents a transaction (in the same order as passed in #sqls). The first item is the transaction itself, the second one is the result.

Contributing

Any contributions are welcome. Feel free to open an issue if you find a bug or a pull request if you want to fix it.