Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it support insert delete update operate? #23

Closed
qhqq opened this issue Jan 26, 2024 · 8 comments
Closed

is it support insert delete update operate? #23

qhqq opened this issue Jan 26, 2024 · 8 comments

Comments

@qhqq
Copy link

qhqq commented Jan 26, 2024

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
.....
`

@jvail
Copy link
Owner

jvail commented Jan 26, 2024

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.

@qhqq
Copy link
Author

qhqq commented Jan 26, 2024

@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 => { })

`

@jvail
Copy link
Owner

jvail commented Jan 26, 2024

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.

@qhqq
Copy link
Author

qhqq commented Jan 26, 2024

@jvail
ok thanks a lot i will try it

@qhqq
Copy link
Author

qhqq commented Jan 29, 2024

@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?

@jvail
Copy link
Owner

jvail commented Jan 29, 2024

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

@qhqq
Copy link
Author

qhqq commented Jan 30, 2024

@jvail
ok ,thanks!!!

@jvail
Copy link
Owner

jvail commented Feb 2, 2024

Seems it is "solved".

@jvail jvail closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants