capacitor-community / sqlite

⚡Capacitor plugin for native & electron SQLite databases.
MIT License
495 stars 118 forks source link

"export 'JsonSQLite' was not found in '@capacitor-community/sqlite' #131

Closed MonicaExplan closed 3 years ago

MonicaExplan commented 3 years ago

I want to use CapacitorSQLite.importFromJson in my project (Capacitor 3, Ionic Vue)

In my code, my import is import { CapacitorSQLite, SQLiteConnection, JsonSQLite } from "@capacitor-community/sqlite"

But I obtain this message "export 'JsonSQLite' was not found in '@capacitor-community/sqlite'

I don't understand...

jepiqueau commented 3 years ago

@MonicaExplan did you look at the Ionic/Vue application starter link is provided in the readme

MonicaExplan commented 3 years ago

Yes I looked at application Starter. But it uses the Hook? I have to install the HooK?

I'm not using ts. I'm not using the hook, And if I stringify "dataToImport" as in Vue starter.

I execute isJsonValid(JSON.stringify(dataToImport))

and I obtain this errore message on runtime: "IsJsonValid: Must provide a Stringify Json object"

jepiqueau commented 3 years ago

@MonicaExplan if you do not use the hook you have to use the API.md so the isJsonValid ({jsonstring:JSON.stringify (dataToImport)}) and follow the same for all other method call

jepiqueau commented 3 years ago

@MonicaExplan sorry my answer was wrong I am travelling and it is not easy to work only with a phone so I will come back to you on this

jepiqueau commented 3 years ago

@MonicaExplan importFromJson and isJsonValid are at the connection level and exportToJson at the DBConnection level. DB = await sqlite.connection (your connection properties) Ret =await sqlite.isJsonValid (JSON.stringify (importData)) await sqlite.importFromJson (JSON.stringify (importData)) DB.exportToJson ("full") Hope this clarify

MonicaExplan commented 3 years ago

@jepiqueau Thanks. I already using connection level.

My problem is with stringify. Infact, if I use this statement below, with Json string in it, it is working fine. But if Ia pass "JSON.stringify (importData)" it fails.

const isValid = await sqlite.isJsonValid( "{\"database\":\"db-from-json\",\"version\":1,\"encrypted\":false,\"mode\":\"full\",\"tables\":[{\"name\":\"users\",\"schema\":[{\"column\":\"id\",\"value\":\"INTEGER PRIMARY KEY NOT NULL\"},{\"column\":\"email\",\"value\":\"TEXT UNIQUE NOT NULL\"},{\"column\":\"name\",\"value\":\"TEXT\"},{\"column\":\"age\",\"value\":\"REAL\"},{\"column\":\"last_modified\",\"value\":\"INTEGER\"}],\"indexes\":[{\"name\":\"index_user_on_name\",\"value\":\"name\"},{\"name\":\"index_user_on_last_modified\",\"value\":\"last_modified DESC\"},{\"name\":\"index_user_on_email_name\",\"value\":\"email ASC, name\",\"mode\":\"UNIQUE\"}],\"values\":[[1,\"Whiteley.com\",\"Whiteley\",40.5,1582536810],[2,\"Jones.com\",\"Jones\",44.2,1582812800],[3,\"Simpson@example.com\",\"Simpson\",69,1583570630],[4,\"Brown@example.com\",\"Brown\",15,1590383895]]},{\"name\":\"messages\",\"schema\":[{\"column\":\"id\",\"value\":\"INTEGER PRIMARY KEY NOT NULL\"},{\"column\":\"title\",\"value\":\"TEXT NOT NULL\"},{\"column\":\"body\",\"value\":\"TEXT NOT NULL\"},{\"column\":\"last_modified\",\"value\":\"INTEGER\"}],\"values\":[[1,\"test post 1\",\"content test post 1\",1587310030],[2,\"test post 2\",\"content test post 2\",1590388125]]}]}" )

Is this a timing problem or something else? Do you have any suggestions, please?

Thanks Monica

jepiqueau commented 3 years ago

@MonicaExplan Can you share your code on github as i do not have any explanation

MonicaExplan commented 3 years ago

@jepiqueau I solved, maybe some Adroid cache...I test it the next day and it works fine. Thanls a lot