margelo / react-native-quick-sqlite Goto Github PK
View Code? Open in Web Editor NEWA fast react-native SQLite library built using JSI
Home Page: https://margelo.io
License: MIT License
A fast react-native SQLite library built using JSI
Home Page: https://margelo.io
License: MIT License
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
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?
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
Hi,
8.0.4
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);
}
open
function doesn't accept a string, but a { name: string; location?: string; }
object
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?
If run android app via detox test, it will failed during the build.
Issue is with duplicate .so libraries.
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"
]
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.
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:
configure
method to allow changing docPath
altogether post install.open
, attach
, and remove
to override the docPath
per operation.global.__QuickSQLiteProxy
and global.nativeCallSyncHook
. Maybe try reading global.appGroupId
?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.
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.
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.
I'm facing the same issue presented here: ospfranco/react-native-quick-sqlite#118
Any idea what can it be? I can help on fixing it but do not have much experience with this kind of configuraitons.
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' });
.
Hey there, Will this library supports in react-native-windows and react-native-macos. if not any plans are there any chances on a plan to support RN-Windows and RN-Macos at some point.
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
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:
import 'reflect-metadata';
in the root index.js file"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.
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:
Apparently that pointer gets populated with the remaining text that is yet to be processed: https://sqlite.org/forum/info/2a9775b88a90d2e6.
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!
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'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
I want to export my database or get my database file path. How can I do it?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.