is it support insert delete update operate?
Closed this issue · 8 comments
hello !
this is my code , not work and no error no info
is it support insert .etc operation or my config is error
const db = await spl .mount('proj', [ { name: 'proj.db', data: new URL('./proj.db', window.location.href).toString() } ]) .mount('data', [ { name: 'relic.gpkg', data: new URL('./r.gpkg?mode=rw', window.location.href).toString() } ]).db() .load('file:data/relic.gpkg?mode=rw') .read(
select enablegpkgmode();
select initspatialmetadata(1);
select PROJ_SetDatabasePath('/proj/proj.db'); -- set proj.db path
`);
db.exec('insert into relic(geom)values(GeomFromText('POINT(lon lat)',4326))').get
.....
`
Hi, could you please reformat/rephrase your question? Maybe tell me what you expect to see in the output? I can only guess: If you insert
then there wont be any result so calling get
is not useful there.
@jvail
thanks for reply !!! i want to use spl.js to insert some data to splitelite or geopackage ,but it does not work code is executed without error but there is no effect in database . no row was added to database, no row was updated.
`
let spl_ = SPL();
const spl = await spl_;
const db = await spl
.mount('proj', [
{ name: 'proj.db', data: new URL('./proj/proj.db', window.location.href).toString() }
])
.mount('data', [
{ name: 'relic.sqlite', data: new URL('./mobiledb.sqlite?mode=rw', window.location.href).toString() }
]).db()
.load('file:data/relic.sqlite?mode=rw')
db.exec('begin').exec("insert into relic(name,geom)values(?,?);", [{ name: 'test', geom: "GeomFromText('POINT(119 37)',4326)" }]).exec('commit').get.first.then(e => { })
`
I think the GeomFromText
wont be evaluated - you need to move it into the query itself. For the result: The commit at the end wont yield anything. Just try the insert and afterwards a select without begin/commit.
Hope that helps.
@jvail
hello ! I did that your method like this
`
let spl_ = SPL();
const spl = await spl_;
const db = await spl
.mount('data', [
{ name: 'relic', data: new URL('./r.gpkg?mode=rw', window.location.href).toString() }
]).db()
.load('file:data/relic?mode=rw');
await db.read(`
insert into relic select 8 as fid, 'taaat' as type , GeomFromText('POINT(108.9177241 33.603679)',4326) as geom ;
insert into relic select 11 as fid, 'a' as type , GeomFromText('POINT(104.9177241 33.603679)',4326) as geom ;
insert into relic select 12 as fid, 'b' as type , GeomFromText('POINT(105.9177241 33.603679)',4326) as geom ;
insert into relic select 13 as fid, 'c' as type , GeomFromText('POINT(105.9177241 33.603679)',4326) as geom ;
insert into relic select 14 as fid, 'd' as type , GeomFromText('POINT(105.9177241 33.603679)',4326) as geom ;
insert into relic select 15 as fid, 'e' as type , GeomFromText('POINT(103.9177241 33.603679)',4326) as geom ;
insert into relic select 16 as fid, 'f' as type , GeomFromText('POINT(107.9177241 33.603679)',4326) as geom ;
insert into relic select 17 as fid, 'g' as type , GeomFromText('POINT(106.9177241 33.603679)',4326) as geom ;
insert into relic (fid,type,geom)values(18,'otooo',geomfromtext('POINT(0 0)',4326));
`)
/////////this is ok in memory,but in real database there is no data which inserted above
await db.exec("select * from relic").get.flat.then(e => {
console.log(e)
}).catch(e => {
console.log(e)
})
} catch (err) {
console.log(err);
}
`
it can insert and query the result in code ,but it seem work in memory .not happend in real database . in database no data was added . is there any method to add data to database?
it can insert and query the result in code ,but it seem work in memory .not happend in real database . in database no data was added . is there any method to add data to database?
In the browser all databases live in memory. The only way to persist your changes is by using db.save()
and then save the buffer somewhere ... or use node.js
Seems it is "solved".