Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-rn-sqlite

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-rn-sqlite

React Native SQLite hooks.For now, only expo-sqlite is supported, but others will be supported in the future.

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

use-rn-sqlite v1.0

SQLite hooks for react-native.(For now only expo-sqlite is supported.)

  • Support for multiple queries in transaction
  • Support for async await

Installation

This package use expo-sqlite, so you have to download with expo-sqlite.

$ npm install --save expo-sqlite use-rn-sqlite

Demo

https://snack.expo.io/HIYBMBGcR

Usage

...

import { useRNSQLite } from 'use-rn-sqlite';

export default function App() {
  const { executeSqlAsync, switchDatabase, closeDatabase } = useRNSQLite('db.db');

  /* execute transaction queries */
  const onInsertPress = async () => {
    const result = await executeSqlAsync(
      ['insert into user(name,age) VALUES("user1",30);'],
      (results, i) => {
        const age = results[i - 1].insertId + 1;
        
        return [`insert into user(name,age) VALUES("user2",${age});`]
      },
      ['select * from user']
    );

    console.log(result);
  }

  /* switch database */
  const onSwitchPress = () => {
    switchDatabase('db2.db');
  }

  useEffect(() => {
    executeSqlAsync([`create table if not exists user (
      id integer primary key not null,
      name text,
      age integer
    )`]);

    return () => {
      closeDatabase();
    }
  },[]);
  
  ...
}

Changelog

See CHANGELOG.md

Keywords

FAQs

Package last updated on 12 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc