我是本机反应的新手。我想构建一个离线 React Native 应用程序来存储用户数据(基本用户详细信息、用户个人文档、图像等)。我已经浏览了一些关于 react-native-sqlite-storage 的文档,我想整合它。但不确定,
android ios react-native redux-persist react-native-sqlite-storage
我在需要 SQLite 存储的 React-Native 应用程序中使用 TypeORM。它工作得非常好,除了一个我整周都在努力解决的错误。
我的方案包含几个对象,它们以一对多、多对一和多对多的关系相互关联。有时,一个实体有多个多对多关系。
我主要在 Android 上开发这个应用程序,在调试模式下它运行良好。保存和读取数据很顺利,它完全符合我的预期。然而,在发布模式下,我不断收到一条非常神秘的错误消息:
[Error: Cyclic dependency: "t"]
Run Code Online (Sandbox Code Playgroud)
TypeORM 通常能很好地告诉你哪里出了问题。然而,在这里,它没有给我任何关于我在哪个实体上犯错的信息。此外,谷歌搜索此错误消息,或在他们的网站上查找,也没有结果。
问题:我整个星期都在为此苦苦挣扎,但没有任何结果。谁能告诉我:
任何帮助将不胜感激。
sqlite android react-native typeorm react-native-sqlite-storage
我想要做的是为我的react-native android应用程序创建多个表,但每次执行代码时它都会返回未知错误(但它可以很好地创建单个表)。
这是我的代码
initDB() {
let db;
return new Promise((resolve) => {
console.log("Plugin integrity check ...");
SQLite.echoTest()
.then(() => {
console.log("Integrity check passed ...");
console.log("Opening database ...");
SQLite.openDatabase(
database_name,
database_version,
database_displayname,
database_size
)
.then(DB => {
db = DB;
console.log("Database OPEN");
db.executeSql('SELECT 1 FROM Feed LIMIT 1').then(() => {
console.log("Database is ready ... executing query ...");
}).catch((error) =>{
console.log("Received error: ", error);
console.log("Database not yet ready ... populating data");
db.transaction((tx) => {
tx.executeSql('CREATE TABLE IF NOT EXISTS Feed (feedId, feedName, …Run Code Online (Sandbox Code Playgroud) 当npx react-native启动时 -- --reset-cache
warn 包react-native-sqlite-storage包含无效配置:不允许“ dependency.platforms.ios.project ”。请使用“ react-native config ”命令验证其是否正确链接,并就此联系软件包维护人员。
我的配置:
"react-native-sqlite-storage": "^3.3.3", // 目前最新的
反应本机.config.js:
module.exports = {
dependency: {
platforms: {
ios: {
project: './platforms/ios/SQLite.xcodeproj'
},
android: {
sourceDir: './platforms/android'
},
windows: {
sourceDir: './platforms/windows',
solutionFile: 'SQLitePlugin.sln',
projects: [
{
projectFile: 'SQLitePlugin/SQLitePlugin.vcxproj',
directDependency: true,
}
],
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
react-native-sqlite-storage 包含无效配置:不允许“dependency.platforms.ios.project”
我正在编写一个严重依赖本地存储的 React-Native 应用程序,并选择了TypeORM来处理这个问题。
我现在正进入我的项目上线的阶段,我想添加需要调整数据模型的新功能。首先,我使用了 react-native-example 项目。我已经在此基础上构建了我的数据模型,现在想对其进行迁移。
似乎没有关于如何在 React-Native 上执行迁移的明确手册/指南。由于我无权访问用户的数据库,因此无法手动运行迁移。到目前为止,我发现连接设置中有一个“migrationsRun”选项,它可以设置为 true,如果需要,强制每次启动应用程序时执行迁移。
那么问题是:应该如何创建实际的迁移,它们应该是什么样子(普通的 sql 查询?),以及我应该把它们放在哪里?
任何有关 react-native 应用程序迁移的指导都会非常有帮助。
sqlite typescript react-native typeorm react-native-sqlite-storage
我使用的是 Android 模拟器,因此我将users.db放在“android/app/src/main/assets/users.db”中。我已经跑了npx react-native link建立链接了。我使用的是带有自动链接功能的 React Native 6.0 以上版本。
我收到“错误:无法打开数据库”:
import React, {Component} from 'react'
import {View, Text, Alert} from 'react-native'
import SQLite from 'react-native-sqlite-storage'
export default class App extends Component {
constructor(props) {
super(props)
SQLite.openDatabase({name:'users', createFromLocation:1}, this.connected, this.failed)
}
connected= () =>{
Alert.alert('Connected with success !')
}
failed= (e) =>{
Alert.alert('Something went wrong !', `${e}`)
}
render(){
return(
<View>
<Text>Testing SQLite</Text>
</View>
)
}
}
Run Code Online (Sandbox Code Playgroud) 我无法在我的应用程序中使用“react-native-sqlite-storage”。我正在使用 expo 来构建纯反应本机应用程序。
我已经尝试过重新安装 React Native,但没有成功。
这是我的 package.json-
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"dependencies": {
"@expo/vector-icons": "^10.0.1",
"axios": "^0.18.0",
"expo": "^32.0.0",
"native-base": "^2.12.1",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-camera": "^2.10.0",
"react-native-camera-kit": "^8.0.0",
"react-native-easy-grid": "^0.2.1",
"react-native-sqlite-storage": "^3.3.10",
"react-navigation": "^3.11.0",
"realm": "^2.28.1"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0"
},
"private": true
}
Run Code Online (Sandbox Code Playgroud) 在 react-native-sqlite-storage 的测试中(参见https://github.com/andpor/react-native-sqlite-storage/blob/master/test/index.ios.promise.js#L141-L149)我发现:
tx.executeSql('INSERT INTO Employees (name, office, department) VALUES ("Sylvester Stallone", 2, 4);');
tx.executeSql('INSERT INTO Employees (name, office, department) VALUES ("Elvis Presley", 2, 4);');
tx.executeSql('INSERT INTO Employees (name, office, department) VALUES ("Leslie Nelson", 3, 4);');
tx.executeSql('INSERT INTO Employees (name, office, department) VALUES ("Fidel Castro", 3, 3);');
tx.executeSql('INSERT INTO Employees (name, office, department) VALUES ("Bill Clinton", 1, 3);');
tx.executeSql('INSERT INTO Employees (name, office, department) VALUES ("Margaret Thatcher", 1, 3);');
tx.executeSql('INSERT INTO Employees (name, office, department) VALUES ("Donald Trump", …Run Code Online (Sandbox Code Playgroud) react-native ×8
react-native-sqlite-storage ×8
sqlite ×5
android ×2
typeorm ×2
ios ×1
reactjs ×1
typescript ×1