Giter VIP home page Giter VIP logo

margelo / react-native-quick-sqlite Goto Github PK

View Code? Open in Web Editor NEW
315.0 3.0 17.0 3.64 MB

A fast react-native SQLite library built using JSI

Home Page: https://margelo.io

License: MIT License

Ruby 0.04% CMake 0.01% C++ 0.50% Java 0.11% JavaScript 0.03% Shell 0.01% C 98.77% Starlark 0.01% Objective-C 0.03% Objective-C++ 0.03% TypeScript 0.48%
jsi lib native react react-native sql sqlite storage

react-native-quick-sqlite's People

Contributors

amika-sq avatar chrispader avatar craftzdog avatar j-piasecki avatar janicduplessis avatar l-u-c-k-y avatar mrousavy avatar ryanlntn avatar savv avatar szymon20000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-quick-sqlite's Issues

Android: SQL execution error: disk I/O error

Hello!

We have started to use this library recently and now we receive this error: "SQL execution error: disk I/O error" for users using Android versions 11 and 12, mostly on Samsung devices.
Does anybody know anything about those issues and what can be done?

Regards,
Ruslan

Support sqlite3_update_hook

We'd like to create a change feed. Whilst some ORM's support this within their own layers e.g. TypeORM Subscribers, we have some complex raw insert/update queries which it doesn't cover easily.

Would it be possible to expose SQLite's sqlite3_update_hook to attach a callback to cover this?

App crashes on reload with No implementation found for clearStateNativeJsi()

My package versions are following:

    "react-native": "0.72.5",
    "react-native-quick-sqlite": "^8.0.5",

Everything works fine except reloads.

This is the complete error:

FATAL EXCEPTION: mqt_native_modules
Process: com.sqlplay, PID: 26910
java.lang.UnsatisfiedLinkError: No implementation found for void com.reactnativequicksqlite.QuickSQLiteBridge.clearStateNativeJsi() (tried Java_com_reactnativequicksqlite_QuickSQLiteBridge_clearStateNativeJsi and Java_com_reactnativequicksqlite_QuickSQLiteBridge_clearStateNativeJsi__)
	at com.reactnativequicksqlite.QuickSQLiteBridge.clearStateNativeJsi(Native Method)
	at com.reactnativequicksqlite.QuickSQLiteBridge.clearState(QuickSQLiteBridge.java:27)
	at com.reactnativequicksqlite.SequelModule.onCatalystInstanceDestroy(SequelModule.java:41)
	at com.facebook.react.bridge.BaseJavaModule.invalidate(BaseJavaModule.java:76)
	at com.facebook.react.bridge.ModuleHolder.destroy(ModuleHolder.java:110)
	at com.facebook.react.bridge.NativeModuleRegistry.notifyJSInstanceDestroy(NativeModuleRegistry.java:108)
	at com.facebook.react.bridge.CatalystInstanceImpl$1.run(CatalystInstanceImpl.java:359)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
	at android.os.Looper.loop(Looper.java:254)
	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
	at java.lang.Thread.run(Thread.java:923

Wrong examples in README

Hi,

Library version

8.0.4

Issue

README contains wrong examples of using the library (or the types need to be reviewed, you decide).

If we take the Simple queries example:

try {
  const db = open('myDb.sqlite');

  const { rows } = db.execute('SELECT somevalue FROM sometable');

  rows.forEach((row) => {
    console.log(row);
  });

  let { rowsAffected } = await db.executeAsync(
    'UPDATE sometable SET somecolumn = ? where somekey = ?',
    [0, 1],
  );

  console.log(`Update affected ${rowsAffected} rows`);
} catch (e) {
  console.error('Something went wrong executing SQL commands:', e.message);
}
  1. open function doesn't accept a string, but a { name: string; location?: string; } object

  2. rows might be undefined and is not an array, it's:

     rows?: {
        /** Raw array with all dataset */
        _array: any[];
        /** The lengh of the dataset */
        length: number;
        /** A convenience function to acess the index based the row object
         * @param idx the row index
         * @returns the row structure identified by column names
         */
        item: (idx: number) => any;
    };

    (taken from the QueryResult type)


I would expect rows to be an array, so I'd like the types to be reviewed, but I'm not sure it's in scope.
Fixing the examples is quicker, for sure.
Interestingly, no one else complained; the same code is present in the old repo.

What do you think?

Add support for detox

Add detox support by exclude some libs in build.gradle

What went wrong

If run android app via detox test, it will failed during the build.
Issue is with duplicate .so libraries.

Possible fix

Excludes from Build.gradle, then detox works.

   excludes = [
              "META-INF",
              "META-INF/**",
              "**/libjsi.so",
              "**/libreact_nativemodule_core.so",
              "**/libturbomodulejsijni.so",
              "**/libc++_shared.so",
              "**/libfbjni.so",
              "**/libhermes_executor.so"     
      ]

Add app group support for iOS

I'm currently working on adding a share extension to an iOS application. For projects that would like to share data between an iOS application and app extension the current installation directory for sqlite won't work. Instead of the application's document directory we would need to use the container directory associated with the security application group. I started a branch to add support for this but I have a couple questions.

  1. What would be the best way to configure the app group identifier to use?

    This is something I'm struggling with as install currently happens on first import. Some ideas I've been toying with:

    1. Add new configure method to allow changing docPath altogether post install.
    2. Add option to open, attach, and remove to override the docPath per operation.
    3. BREAKING CHANGE Stop installing on import and instead require manual installation/configuration allowing this to be passed in from JS similar to 1.
    4. Use a global var. We already have global.__QuickSQLiteProxy and global.nativeCallSyncHook. Maybe try reading global.appGroupId?
    5. Since this is iOS only use a plist value and setup a postlink hook similar to how react-native-code-push does it. Might even be able to just read the app group identifiers directly here.
    6. Similarly provide config via the Podfile.
  2. Should this library handle migrating previous data to the new location if an app group id is provided after data has previously been stored in the documents directory?

    It seems like this should be possible. If a file already exists in the app's documents directory but not yet in the app group container directory it could be copied or moved on open. Alternatively this could be handled from outside this library using react-native-fs.

  3. Would we want to support multiple install locations? Is there a use case for using both the application's document directory and the app group directory? What about using separate app group directories for different app extensions?

    I believe this would require solution 2 or 3 above. I'm not sure how useful it would be. I don't currently see a need for it.

History loss upon migration

Hello, thank you for taking ownership of the library. I’m wondering if you could fork the opsfranco repo and maintain history.

Maintaining history has a lot of benefits and it’s what allowed me to contribute a minor fix to the opsfranco repo.

Thanks for considering it.

API Documentation incorrectly describes how to open a database

The code shown in the README under the API header const db = open('myDb.sqlite'); throws the error [react-native-quick-sqlite][open] database name must be a string.

Only upon reading some open issues, I figured out the actual way to open a database is via const db = open({ name: 'myDb.sqlite' });.

Base quick-sqlite module not found. Maybe try rebuilding the app.

Trying to run on android through Expo.

Expo Version 48.0.18
RN: 0.71.8

Full error:

Error: Base quick-sqlite module not found. Maybe try rebuilding the app., js engine: hermes
Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes


Can't init database [immutable and has been frozen]

Hi,
I got this issue when trying to use react-native-quick-sqlite and typeorm

Error: You attempted to set the key `_y` with the value `1` on an object that is meant to be immutable and has been frozen.

This is my code

// database.ts
import { DataSource } from 'typeorm/browser';
import { typeORMDriver } from 'react-native-quick-sqlite';
import { Book } from './entities/book';

export const appDataSource = new DataSource({
  type: 'react-native',
  database: 'typeormdb',
  location: '.',
  driver: typeORMDriver,
  entities: [Book],
  synchronize: true,
});

// book.ts
import 'reflect-metadata';
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm/browser';
import { BaseEntity } from 'typeorm';

@Entity()
export class Book extends BaseEntity {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column()
  title!: string;
}

And this issue showing when I trying to call this function appDataSource.initialize()

Note:

  • I already setup follow the docs add import 'reflect-metadata'; in the root index.js file
  • Packages version:
"react-native-quick-sqlite": "7.0.0",
"react-native": "0.68",
"typeorm": "0.3.11",
 "reflect-metadata": "^0.1.13",

This issue showing on iOS, I didn't test on Android yet.

Cannot execute multiple statements with one call

Consider the following sql script:

CREATE TABLE foo (id INTEGER);
CREATE TABLE bar (id INTEGER);

With the current interface, only the first statement will be executed and no error is given. I would've expected to have the whole sql script executed, or at least to get an error.

I digged through the code, and found out that the pzTail parameter is unused in the sqliteExecute's prepare call:

int statementStatus = sqlite3_prepare_v2(db, query.c_str(), -1, &statement, NULL);

Apparently that pointer gets populated with the remaining text that is yet to be processed: https://sqlite.org/forum/info/2a9775b88a90d2e6.

changing location property is not showing the DB

I am trying to save the DB file inside the App Data folder (e.g. /storage/emulated/0/Android/data/com.package.name). And I have this code:

// other imports
import { QuickSQLiteConnection, open } from "react-native-quick-sqlite";

// get the app directory
const externalDirectory = RNFS.ExternalDirectoryPath; // --> /storage/emulated/0/Android/data/com.package.name/files location

// open the db
const db = open({ name: "default.db", location: externalDirectory });

This opens the DB fine, I am not able to see any file inside the above mentioned location. And, if I change the location property to any other directory (e.g. RNFS.DownloadDirectoryPath), this also not showing any DB, but if I revert to old location, I still have the older data.

My requirement is that I want to give an option to the user to export (backup) the local database, so that they can import it later, or onto any other devices. How can I achieve this?

Thank you in advance!

Missing compatibility with rn 0.74RC

While upgrading react native to 0.74.0-rc.2 I have encountered an error related to Folly files missing.
Confirmed on fresh react-native project generated by using npx react-native@next init RN0740RC2 --version 0.74.0-rc.2

Screenshot 2024-03-11 at 16 56 00

Expo SDK49 upgrade errors

After upgrading to SDK49 I started getting the following error when using expo run:ios:

❌  (ios/Pods/Headers/Public/react-native-quick-sqlite/sqlite3.h:723:8)

  721 | */
  722 | typedef struct sqlite3_file sqlite3_file;
> 723 | struct sqlite3_file {
      |        ^ redefinition of 'sqlite3_file'
  724 |   const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
  725 | };
  726 | 

This is an excerpt of the full error, as this block repeats for the various SQLite structs. Reverting to SDK48 solves the problem.

I can't find file database

  • I use library to create database
  • but I can't find file data of my database
  • I need it to connect by dbeaver. I want test query before code.
  • help me. please

clearState doesn't take care of pending threads

I've noticed that the sqlite lib crashes when codepush restarts the app, if there are a pending async queries.

The reason is that it tries to use a runtime that doesn't exist anymore, crashing here.

I had previously tried to mitigate this issue with #16. While correct, it still allows pending executions to complete, causing these crashes.

One way to fix this is to kill ThreadPool's threads from osp::clearState().

@ospfranco any thoughts?

Full stack trace

facebook::jsi::Object::Object (jsi.h:658)
createSequelQueryExecutionResult (JSIHelper.cpp:135)
const::lambda::operator() (bindings.cpp:240)
std::__1::__invoke<T> (type_traits:3918)
std::__1::__invoke_void_return_wrapper<T>::__call<T> (invoke.h:61)
std::__1::__function::__alloc_func<T>::operator() (function.h:178)
std::__1::__function::__func<T>::operator() (function.h:352)
std::__1::__function::__value_func<T>::operator() (function.h:505)
std::__1::function<T>::operator() (function.h:1182)
facebook::react::Instance::JSCallInvoker::scheduleAsync::lambda::operator() (Instance.cpp:295)
std::__1::__invoke<T> (type_traits:3918)
std::__1::__invoke_void_return_wrapper<T>::__call<T> (invoke.h:61)
std::__1::__function::__alloc_func<T>::operator() (function.h:178)
std::__1::__function::__func<T>::operator() (function.h:352)
std::__1::__function::__value_func<T>::operator() (function.h:505)
std::__1::function<T>::operator() (function.h:1182)
facebook::react::NativeToJsBridge::runOnExecutorQueue::lambda::operator() (NativeToJsBridge.cpp:310)
std::__1::__invoke<T> (type_traits:3918)
std::__1::__invoke_void_return_wrapper<T>::__call<T> (invoke.h:61)
std::__1::__function::__alloc_func<T>::operator() (function.h:178)
std::__1::__function::__func<T>::operator() (function.h:352)
std::__1::__function::__value_func<T>::operator() (function.h:505)
std::__1::function<T>::operator() (function.h:1182)
facebook::react::tryAndReturnError (RCTCxxUtils.mm:74)
facebook::react::RCTMessageThread::tryFunc (RCTMessageThread.mm:69)
std::__1::__function::__value_func<T>::operator() (function.h:505)
std::__1::function<T>::operator() (function.h:1182)
facebook::react::RCTMessageThread::runAsync (RCTMessageThread.mm:45)
CoreFoundation
+0x0355c4
<redacted>
CoreFoundation
+0x033ee8
<redacted>
CoreFoundation
+0x031de8
<redacted>
CoreFoundation
+0x031a04
CFRunLoopRunSpecific
+[RCTCxxBridge runRunLoop] (RCTCxxBridge.mm:337)
Foundation
+0x0a805c
<redacted>
libsystem_pthread
+0x00218c
_pthread_start

Unable to generate migration

Many thanks for providing and maintaining this awesome library!
I have followed the docs and was successful to set it up and write/read data from sqlite with TypeORM.

I am trying to generate a migration for production but I am struggling with getting it to run.

Does anyone has advice how to implement a migration?

Here are things that I have tried.

dataSource.ts

import { typeORMDriver } from 'react-native-quick-sqlite';
import { DataSource } from 'typeorm';

const dataSource = new DataSource({
  type: 'react-native',
  database: 'typeormdb',
  location: '.',
  driver: typeORMDriver,
  entities: [
    // entities
  ],
  logging: true,
  // synchronize: true, // only have it in dev, otherwise use migrations!
  migrations: [],
  migrationsRun: true,
});

export default dataSource;

Commands:

typeorm migration:generate -d src/db/dataSource/index.ts src/db/migrations
npx typeorm-ts-node-commonjs migration:generate -d src/db/dataSource/index.ts src/db/migrations
npx typeorm-ts-node-esm migration:generate -d src/db/dataSource/index.ts src/db/migrations
npx typeorm migration:generate -d ./src/db/dataSource/index.ts ./src/db/migrations

Thanks a lot


Edit: After running a few more experiments I was able to narrow the problem down to the typeORM driver.

Using exactly the same setup without the typeORM driver and postgres is working!

The app is running fine overall, reading and writing is working, but generation of the migration is not working.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.