Reputation: 518
i am using expo to build a app.
here,
`import * as SQLite from 'expo-sqlite';
const db = SQLite.openDatabase("db.db");
is not working while
import { SQLite } from "expo-sqlite";
is working.
when i use the first method, it is getting SQLite.openDatabase is not a function error.
actually what is the difference with these? anyone have an idea?
Upvotes: 1
Views: 2618
Reputation: 12243
When you do import * as SQLite from 'expo-sqlite';
you are actually importing all the modules from the expo-sqlite by writing * as SQLite , and its stored as SQLite variable which then you are using to create an openDatabase.
But when you do import { SQLite } from "expo-sqlite";
you are only importing the SQLite module from the expo-sqlite package. And after that you are using it to create a database.
Basically its like sometimes in some file you have multiple functions like suppose App.js
export const add =() => {
}
export const bol = () => {
}
Then suppose in Home.js you need to import ,
So if you want only the add function then you will do
import {add} from 'App.js'
or you want both so <
import {add,bol} from 'App.js'
and another way of importing both is by
import * as Func from 'App.js'
And now you can access each by Func.add and Func.bol
Hope it helps. feel free for doubts
Upvotes: 2