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

vue-data-storage-sqlite-hook

v3.0.0

Published

Vue Hook for Capacitor Data Storage SQLite

Downloads

60

Readme

Maintainers

| Maintainer | GitHub | Social | | ----------------- | ----------------------------------------- | ------ | | Quéau Jean Pierre | jepiqueau | |

Installation

npm install --save capacitor-data-storage-sqlite
npm install --save-dev vue-data-storage-sqlite-hook

Applications demonstrating the use of the plugin and the vue hook

Vue 3

Ionic/Vue

Usage

Import the hook from its own path:

 import { useStorageSQLite } from 'vue-data-storage-sqlite-hook/dist';

in the App.vue file

<template>
  <ion-app>
    <ion-router-outlet />
  </ion-app>
</template>

<script lang="ts">
import { IonApp, IonRouterOutlet } from '@ionic/vue';
import { defineComponent, getCurrentInstance, onMounted } from 'vue';
import { useStorageSQLite } from 'vue-data-storage-sqlite-hook/dist';

export default defineComponent({
  name: 'App',
  components: {
    IonApp,
    IonRouterOutlet
  },
  setup() {
    const app = getCurrentInstance();
    onMounted(async () => {
      if( app != null) {  
        app.appContext.config.globalProperties.$storageSqlite = useStorageSQLite();
      }
    });
  }
});
</script>

And then use the hook inside a component


<template>
  <div id="default-container">
    <div id="log">
        <pre>
          <p>{{log}}</p>
        </pre>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, getCurrentInstance, onMounted } from 'vue';
import { StorageSQLiteHook } from 'vue-data-storage-sqlite-hook/dist';
import { useState } from '@/composables/state';
import { Dialog } from '@capacitor/dialog';

export default defineComponent({
  name: 'DefaultTest',
  setup() {
    const [log, setLog] = useState("");
    const app = getCurrentInstance();
    const storageSqlite: StorageSQLiteHook = app?.appContext.config.globalProperties.$storageSqlite;
    let errMess = "";
    const showAlert = async (message: string) => {
        await Dialog.alert({
        title: 'Error Dialog',
        message: message,
        });
    };
    const defaultTest = async (): Promise<boolean>  => {
      setLog(log.value.concat("**** Starting Test Default Store ****\n"));
      try { 
        // open store
        await storageSqlite.openStore({});
        setLog(log.value.concat("openStore was successful \n"));
        // clear the store 
        await storageSqlite.clear();
        setLog(log.value.concat("clear was successful \n"));
        // store a string 
        await storageSqlite.setItem("session","Session Opened");
        const session = await storageSqlite.getItem('session');
        if(session != "Session Opened") {
          errMess = `setItem/getItem session failed`;
          return false;
        } else {
          setLog(log.value.concat("setItem/getItem session was successful \n"));
        }
        // store a JSON Object in the default store
        const data = {'a':20,'b':'Hello World','c':{'c1':40,'c2':'cool'}};
        await storageSqlite.setItem("testJson",JSON.stringify(data));
        const testJson = await storageSqlite.getItem("testJson");
        if( testJson != JSON.stringify(data) ) {
          errMess = `setItem/getItem testJson failed`;
          return false;
        } else {
          setLog(log.value
                .concat("setItem/getItem testJson was successful \n"));
        }
        // store a number in the default store
        const data1 = 243.567;
        await storageSqlite.setItem("testNumber",data1.toString());
        // read number from the store
        const testNumber = Number(await storageSqlite.getItem("testNumber"));
        if( testNumber != data1 ) {
          errMess = `setItem/getItem testNumber failed`;
          return false;
        } else {
          setLog(log.value
              .concat("setItem/getItem testNumber was successful \n"));
        }
        // isKey tests
        const iskey: boolean = await storageSqlite.isKey('testNumber');
        if( !iskey ) {
          errMess = `isKey testNumber failed`;
          return false;
        } else {
          setLog(log.value.concat("isKey testNumber was successful \n"));
        }
        const iskey1: boolean = await storageSqlite.isKey('foo');
        if( iskey1 ) {
          errMess = `isKey foo failed`;
          return false;
        } else {
          setLog(log.value.concat("isKey foo was successful \n"));
        }
        // Get All Keys
        const keys: string[] = await storageSqlite.getAllKeys();
        if(keys.length != 3) {
          errMess = `getAllKeys failed`;
          return false;
        } else {
          for(let i = 0; i< keys.length;i++) {
            setLog(log.value.concat(' key[' + i + "] = " + keys[i] + "\n"));
          }
          setLog(log.value.concat("getAllKeys was successful \n"));
        }
        // Get All Values
        const values: string[] = await storageSqlite.getAllValues();
        if(values.length != 3) {
          errMess = `getAllValues failed`;
          return false;
        } else {
          for(let i = 0; i< values.length;i++) {
            setLog(log.value.concat(' key[' + i + "] = " + values[i] + "\n"));
          }
          setLog(log.value.concat("getAllValues was successful \n"));
        }
        // Get All KeysValues
        const keysvalues: any[] = await storageSqlite.getAllKeysValues();
        if(keysvalues.length != 3) {
          errMess = `getAllKeysValues failed`;
          return false;
        } else {
          setLog(log.value.concat("getAllKeysValues was successful \n"));
        }
        // Remove a key 
        await storageSqlite.removeItem('testJson')
        setLog(log.value.concat("removeItem was successful \n"));

        // Get All Keys
        const keys1: string[] = await storageSqlite.getAllKeys();
        if(keys1.length != 2) {
          errMess = `getAllKeys after removeItem failed`;
          return false;
        } else {
          for(let i = 0; i< keys1.length;i++) {
            setLog(log.value.concat(' key[' + i + "] = " + keys1[i] + "\n"));
          }
          setLog(log.value
                .concat("getAllKeys after removeItem was successful \n"));
        }
        setLog(log.value
          .concat("\n**** Test Default Store was successful ****\n")); 
        return true;
      } catch (err) {
          errMess = `${err.message}`;
          return false;
      }
    };
    onMounted(async () => {
        // Running the test
        const retDefaultTest: boolean = await defaultTest();
        console.log(`retDefaultTest ${retDefaultTest}`);
        if(!retDefaultTest) {
            setLog(log.value
                .concat("* defaultTest failed *\n"));
            setLog(log.value
                    .concat("\n* The set of tests failed *\n"));
            await showAlert(errMess);
        } else {
            setLog(log.value
                .concat("\n* The set of tests was successful *\n"));
        }

    });

    return { log, errMess };
  }

});
</script>

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!