import { StatusBar } from "expo-status-bar";
import API from "../../function/API";
import { useQueryClient, useQuery } from "@tanstack/react-query";
import dayjs from "dayjs";
import NetInfo from "@react-native-community/netinfo";
import { database } from "../../assets/Model/db";
import { WriterInterface } from "@nozbe/watermelondb/Database/WorkQueue";
import AsyncStorage from "@react-native-async-storage/async-storage";
the code call function onCreate
import { StatusBar } from "expo-status-bar"; import API from "../../function/API"; import { useQueryClient, useQuery } from "@tanstack/react-query"; import dayjs from "dayjs"; import NetInfo from "@react-native-community/netinfo"; import { database } from "../../assets/Model/db"; import { WriterInterface } from "@nozbe/watermelondb/Database/WorkQueue"; import AsyncStorage from "@react-native-async-storage/async-storage";
const Home = ({ navigation }) => { // const masterCompanies = database.collections.get("master_company"); const database = database.get("master_company");
const onCreate = async () => { try{ const newMasterCompany = await database .get("master_company") .create((master_company) => { master_company.name = "PT. Rimba Sejahtera"; master_company.isSync = false; master_company.isConnected = false; master_company.created_at = new Date(); master_company.deleted_at = new Date(); master_company.updated_at = new Date(); }); console.log(newMasterCompany ); } catch (error) { console.error('error', error) } // \ };
package json { "name": "revaapp", "version": "1.0.0", "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web" }, "dependencies": { "@expo/webpack-config": "^19.0.0", "@nozbe/watermelondb": "^0.27.1", "@nozbe/with-observables": "^1.6.0", "@react-native-async-storage/async-storage": "^1.19.4", "@react-native-community/cli-platform-android": "^12.1.1", "@react-native-community/netinfo": "^11.1.0", "@react-navigation/bottom-tabs": "^6.5.9", "@react-navigation/native": "^6.1.8", "@react-navigation/stack": "^6.3.18", "@reduxjs/toolkit": "^1.9.7", "@tanstack/react-query": "^5.8.4", "axios": "^1.6.1", "dayjs": "^1.11.10", "expo": "^49.0.21", "expo-constants": "~14.4.2", "expo-splash-screen": "~0.20.5", "expo-sqlite": "~11.3.3", "expo-status-bar": "~1.6.0", "formik": "^2.4.5", "prebuild": "^12.1.0", "react": "18.2.0", "react-datepicker": "^4.21.0", "react-dom": "18.2.0", "react-native": "0.72.6", "react-native-auto-height-image": "^3.2.4", "react-native-element-dropdown": "^2.10.0", "react-native-gesture-handler": "~2.12.0", "react-native-reanimated": "~3.3.0", "react-native-safe-area-context": "4.6.3", "react-native-select-dropdown": "^3.4.0", "react-native-sqlite-2": "^3.6.2", "react-native-toast-message": "^2.1.7", "react-native-web": "~0.19.6", "react-navigation-stack": "^2.10.4", "react-redux": "^8.1.3", "yarn": "^1.22.19", "yup": "^1.3.2" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/plugin-proposal-decorators": "^7.23.5" }, "private": true }
The schema import { appSchema, tableSchema } from "@nozbe/watermelondb"; import { unsafeExecuteSql } from "@nozbe/watermelondb/Schema/migrations";
export default mySchema = appSchema({ version: 2, tables: [ tableSchema({ name: "master_company", columns: [ // { name: "id_master_companies", type:"string",isIndexed: true }, { name: "name", type: "string" }, { name: "isSynced", type: "boolean" }, { name: "isConnected", type: "boolean" }, { name: "created_at", type: "number" }, { name: "deleted_at", type: "number" }, { name: "updated_at", type: "number" }, ], unsafeSql: sql => sql.replace(/create table [^)]+)/, '$& without rowid'),
] });
any idea? i though already install watermelondb properly following documentation