how to use expo-sqlite react-native application problem

I’m developing an application and I would like to use a db to store data so I don’t constantly ask it to the server, but I’m having problems with expo-sqlite, can anyone explain me what I’m doing wrong ?

i have a file database.js

`import * as SQLite from 'expo-sqlite';

const db = SQLite.openDatabase('myDatabase.db');

export const createTables = () => {db.transaction(tx => {tx.executeSql(CREATE TABLE IF NOT EXISTS users ( uid INTEGER PRIMARY KEY, picture TEXT, pversion INTEGER ));});}; then I have a viewmodel for data management where I would use the storemanager`import { useEffect, useState } from 'react';import { fetchTopUsers, userDetails } from '../api';import { useSession } from './../utils/SessionManager';import StorageManager from './../utils/StorageManager';

export const useUserListViewModel = () => {// const [userList, setUserList] = useState([]);const [isLoading, setIsLoading] = useState(true);const { sid } = useSession();const [userTopList, setUserTopList] = useState([]);

useEffect(() => {const initializeAndFetchData = async () => {try {if (sid) {const users = await fetchTopUsers(sid);StorageManager.initialize();await updateUsers(users);} else {console.log("UserVMlist sid mancante o non valido");}} catch (error) {console.error('Errore durante l'inizializzazione o il recupero dei dati:', error);} finally {setIsLoading(false);}};

initializeAndFetchData();

}, [sid]);`

this is my storagemanager

`import { createTables, insertItem, getItems, deleteItem } from './../database';

class StorageManager {

static initialize() {
createTables();
}

static addItem(value) {
return insertItem(value);
}

static fetchItems() {
return getItems();
}

static removeItem(id) {
return deleteItem(id);
}
}

export default StorageManager;`

these are my dependencies
"dependencies": { "@expo/vector-icons": "^14.0.2", "@react-native-async-storage/async-storage": "^1.23.1", "@react-native-community/masked-view": "^0.1.11", "@react-navigation/bottom-tabs": "^6.5.19", "@react-navigation/native": "^6.1.12", "@react-navigation/stack": "^6.3.23", "axios": "^1.6.8", "expo": "^51.0.5", "expo-location": "~16.5.5", "expo-sqlite": "~14.0.3", "expo-status-bar": "~1.11.1", "expo-vector-icons": "^10.0.1", "react": "18.2.0", "react-native": "^0.74.1", "react-native-gesture-handler": "~2.14.0", "react-native-maps": "^1.11.3", "react-native-reanimated": "^3.7.1", "react-native-safe-area-context": "^4.9.0", "react-native-screens": "^3.29.0" },

I expect it to work, but I have these two errors and I don’t understand how to fix it

ERROR TypeError: SQLite.openDatabase is not a function (it is undefined), js engine: hermes
ERROR 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

New contributor

Gianmarco Lobaccaro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật