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

@universal-health-chain/pouchdb-adapter-react-native-sqlite-ts

v3.0.1

Published

PouchDB adapter using ReactNative SQLite Plugin as its data store.

Downloads

5

Readme

logo

@universal-health-chain/pouchdb-adapter-react-native-sqlite-ts (typescript)

PouchDB adapter using ReactNative SQLite as its backing store. Forked from https://github.com/craftzdog/pouchdb-adapter-react-native-sqlite, but using Typescript and @universal-health-chain/pouchdb-adapter-websql-core-ts (typescript).

Why?

SQLite storage performs much faster than AsyncStorage, especially with secondary index. Here is benchmark results:

| 1) allDocs speed | min | max | mean | | ------------------ | ---- | ---- | ---- | | AsyncStorage | 72ms | 94ms | 77ms | | SQLite | 27ms | 39ms | 28ms |

| 2) query speed | min | max | mean | | ---------------- | ------- | ------- | ------- | | AsyncStorage | 1,075ms | 1,117ms | 1,092ms | | SQLite | 33ms | 39ms | 35ms |

  • Device: iPhone 6s
  • Documents: 434
  • Update seq: 453
  • Iterations: 100
  • Used options: { include_docs: true }

On Simulator

  • Device: iPad Pro 9.7" (Simulator) - iOS 10.3.2
  • Documents: 5000

| 3) bulkDocs speed | total | mean | | ------------------- | -------- | ------ | | AsyncStorage | 25.821ms | 5.16ms | | SQLite | 22.213ms | 4.44ms |

| 4) allDocs speed | total | mean | | ------------------ | --------- | ------- | | AsyncStorage | 189,379ms | 37.87ms | | SQLite | 30,527ms | 6.10ms |

  • allDocs options: { include_docs: true, attachments: true }
  • Using this test script

How to use it

(based on https://dev.to/craftzdog/a-performant-way-to-use-pouchdb7-on-react-native-in-2022-24ej)

  1. Install these packages (use expo install, npm i or yarn add):
  • expo install events react-native-get-random-values react-native-quick-base64
  • expo install pouchdb-core pouchdb-replication pouchdb-mapreduce
  • expo install pouchdb-adapter-http react-native-quick-sqlite
  1. Add the new UHC packages, refactored to typescript to solve both jest and import problems in web (for expo):
  • expo install @universal-health-chain/pouchdb-adapter-react-native-sqlite-ts
  • expo install @universal-health-chain/react-native-quick-websql-ts
  1. Then:
  • npx pod-install
  1. Create the shim.js file (see the link) and import it in the first line in the index.js file of the project (as specified in the above link).

    import {shim} from 'react-native-quick-base64'
    
    shim()
    
    // Avoid using node dependent modules
    process.browser = true
  2. Edit your babel.config.js like so:

    module.exports = {
      presets: ['module:metro-react-native-babel-preset'],
      plugins: [
        [
          'module-resolver',
          {
            alias: {
              'pouchdb-collate': '@craftzdog/pouchdb-collate-react-native',
            },
          },
        ],
      ],
    }
  3. To initialize, create pouchdb.ts like so:

    import 'react-native-get-random-values'
    
    // PouchDB required imports
    import PouchDB from 'pouchdb-core'
    import HttpPouch from 'pouchdb-adapter-http'
    import replication from 'pouchdb-replication'
    import mapreduce from 'pouchdb-mapreduce'
    
    // using PouchDB with the "@universal-health-chain" packages to avoid problems with web in expo
    import { createPlugin } from '@universal-health-chain/pouchdb-adapter-react-native-sqlite-ts'
    
    const dbConfigNative: PouchDB.Configuration.DatabaseConfiguration = {
      adapter: 'react-native-sqlite'
    };
    
    // you can check if the platform is "web" or not (native)
    export const db = await openPouchDBWithNativeAdapterSQLite("dbName", dbConfigNative);
    
    async function openPouchDBWithNativeAdapterSQLite(
      dbName: string,
      dbConfig: PouchDB.Configuration.DatabaseConfiguration
    ): Promise<PouchDB.Database> {
    
      // importing the class for react native
      const nativeSQLite = require('@universal-health-chain/react-native-quick-websql-ts');
         
      // instantiate the plugin for react native
      const pluginSQLite = new nativeSQLite.SQLitePlugin();
         
      // create the plugin for react native
      const adapterSQLite = createPlugin(pluginSQLite);
         
      PouchDB.plugin(HttpPouch)
        .plugin(replication)
        .plugin(mapreduce)
        .plugin(adapterSQLite)
    
      // creating the database client (it opens/creates the database)
      const pouchDB = new PouchDB(dbName, dbConfig);
      return pouchDB
    };
  4. Note - do not use these packages to avoid jest and web problems when importing them:

  • pouchdb-adapter-react-native-sqlite
  • react-native-quick-websql

Changelog