New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@carlosrpj/expo-raw-sql-migrations

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@carlosrpj/expo-raw-sql-migrations

Migration tool to use raw sql for SQLite / react-nativ expo.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-native-expo-raw-sql-migrations

SQLite migrater with raw SQL for expo-managed React Native app using React Hooks and TypeScript.

Installation

yarn add react-native-expo-raw-sql-migrations
# or
npm install --save react-native-expo-raw-sql-migrations

Usage

Standard

Automatically migrate.

  1. Ready to DB object and migration JSON schema.
  2. Wrap with Provider Component.
  3. Handle to fetch DB with useMigrate custom hook.
// app.tsx
import React from 'react'
import { MigrationProvider, Migration } from "react-native-expo-raw-sql-migrations";
import * as SQLite from "expo-sqlite";

// 1) Ready to db and migration.
export const db = SQLite.openDatabase("myApp.db", "1"); // args are dbname, db-version.
export const migrations: Migration[] = [
  {
    name: "202004021800",
    query:
      "CREATE TABLE cycles (id TEXT PRIMARY KEY, startedAt TEXT, endedAt TEXT, createdAt TEXT, updatedAt TEXT)",
  },
  {
    name: "202004022100",
    query:
      "CREATE TABLE kpts (id TEXT PRIMARY KEY, cycleID TEXT, type TEXT, text TEXT, createdAt TEXT, updatedAt TEXT, FOREIGN KEY(cycleID) REFERENCES cycles(id))",
  },
];

// 2) Wrap provider
//    Execute to migrate automatically.
const App = () => {
  return(
    <MigrationProvider db={db} migrations={migrations}>
      { /* children components ... */ }
    </MigrationProvider>
  )
}

export default App;
// SomethingComponent.tsx
import React from 'react'
import { useMigrate } from "react-native-expo-raw-sql-migrations";

const fetchUser = () => { /* fetch data from db */ }

export const SomethingComponent = () => {
  // isFinished as flag will be true after migration.
  const { isFinished } = useMigrate()

  React.useEffect(() => {
    // 3) Handle operation for db.
    //    These operation for db should execute after migration.
    if(isFinished){
      fetchUser()
    }
  }, [isFinished, fetchUser])
}

Advanced

If you would like to handle migration logic yourself, pass startsBootstrap option to Provider Component. e.g<MigrationProvider options={{ startsBootstrap: false }}>{...}</MigrationProvider>

Used by

This package is used by Keputo - KPT method - Keep/Problem/Try as expo mobile app.

Acknowledges

Keywords

FAQs

Package last updated on 09 Aug 2023

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