gpt4 book ai didi

javascript - 博览会- native react : there is way to see the content of the expo FileSystem and also delete content from there?

转载 作者:行者123 更新时间:2023-12-03 14:15:36 27 4
gpt4 key购买 nike

有办法查看文件系统的内容并从中删除内容吗?

我在世博文件系统中有数据,我需要:

  1. 查看文件系统内部,因为我不知道如何找到这个文件,因为我使用带有二维码扫描的 expo 客户端 sdk,并且我不明白如何在那里找到这个文件。
  2. 我想知道如何从文件系统中删除内容。
  3. 我如何将 sqlite 数据库视为真实的表?

这是我的例子:

saveDbData = async () => {
const { data, isLoaded } = this.state;
for (let i = 0; i < data.length; i++) {
const mediaData = data[i];
const dbResult = await insertPlace(
mediaData.artist,
mediaData.image,
mediaData.title,
mediaData.url
);
console.log("SQL", `${FileSystem.documentDirectory}/SQLite/places.db`);
}
const fetchawesome = await fetchPlaces();
console.log(fetchawesome)
};

最佳答案

由于您提出了三个问题,我会尽力一一解答并提供可能的解决方案。

look inside FileSystem because i dont know how to find this file because i work with the expo client sdk with the qr code scan and i dont understand how can i find this file there .

您可以使用 expo 中的 FileSystem 包访问文件系统。以下是您可以如何做到这一点。先导入包。

import * as FileSystem from "expo-file-system";

然后你可以像这样找到文件的URI

const { uri } = await FileSystem.getInfoAsync(
`${FileSystem.documentDirectory}SQLite/${"yourDB.db"}`
);

I want to know how to delete contents from the file system.

如果您有权访问文件的位置或URI,则可以删除该文件。这就是您可以删除它的方法。它返回一个 promise 。

FileSystem.deleteAsync(fileUri)

how can I see the SQLite database as a real table?

这是一个棘手的部分,因为由于您使用 Android 手机通过 expo 运行应用程序,因此您将无法直接访问 db。您可以做的一件事是将 db 移动到您有权访问的其他位置,并使用 expo 中的 Sharing API 来保存或发送通过电子邮件或任何其他方式将db发送给您自己。

 import * as Sharing from "expo-sharing"; 

let documenturi = `${FileSystem.documentDirectory}/yourDB.db`;
await FileSystem.copyAsync({
from: uri,
to: documenturi,
});
Sharing.shareAsync(documenturi);

您可以将其作为一个在按下 Button 时触发的函数,您甚至可以将其放入 useEffect 或生命周期方法中,以便在屏幕加载时触发。

关于javascript - 博览会- native react : there is way to see the content of the expo FileSystem and also delete content from there?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61381082/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com