GithubHelp home page GithubHelp logo

Comments (7)

WebReflection avatar WebReflection commented on May 31, 2024

you're right, both .close() and .create_function(name, func) are not exposed/available, but I guess these should.

from sqlite-worker.

onlyfortesting avatar onlyfortesting commented on May 31, 2024

+1

I need the classic db.prepare because I usually create function like this:

function insertNote(toInsert) {
    const keys = Object.keys(toInsert)

    // Doing this because some columns are optional
    const info = db.prepare(`INSERT INTO note
        (${keys.join(',')})
        VALUES
        (${keys.map(k => '@' + k).join(',')})
    `).run(toInsert)

    ...
}

I cannot make it work with sqlite-tag. Are there any workaround?

from sqlite-worker.

WebReflection avatar WebReflection commented on May 31, 2024

@onlyfortesting what has prepare to do with exposure of close and create function? that + the fact you don't need to prepare anything with sqlite-tag, that's the whole idea, but transaction with commit eventually works.

from sqlite-worker.

WebReflection avatar WebReflection commented on May 31, 2024

@twoxfh both close and create_function are in. Bear in mind when used through the Worker create_function can accept only pure functions without any outer scope access, because functions don't survive the post message dance. This limitation does not exist when used directly through the initializator.

from sqlite-worker.

twoxfh avatar twoxfh commented on May 31, 2024

Great..I tested as well. Not sure if it needs mentioning, if an error is thrown in a custom function the current and all queries after, stop.. You can use it to count running time on queries and throw errors for long running queries. Of course if it's a long running row evaluation it does not help. Emscripten is working on WASMFS which will use pthreads and the you can kill the thread for row evaluation issues.

from sqlite-worker.

WebReflection avatar WebReflection commented on May 31, 2024

if an error is thrown in a custom function the current and all queries after, stop

uhm ... I should likely wrap that in a try/catch then .. would that fix the issue?

from sqlite-worker.

onlyfortesting avatar onlyfortesting commented on May 31, 2024

@WebReflection Yep. It has nothing to do with those methods. But, since OP also asked if there is a way to interact directly with the sqlitedb instance (which I also wanted to do) so I thought I'd rather comment on this issue as well than creating a new one.

Anyway, I have found solution to my problem. Basically, I'm trying to do this query with sqlite-tag

const keys = Object.keys(toInsert)
db.query`
  INSERT INTO notes (${db.raw`${keys.join(',')}`})
  VALUES (${keys.map(c => toInsert[c]).joins(db.raw`,`)}) -- this part throws`

Which doesn't work. So, I originally thought it can't be done without exposing .prepare. Turns out I just don't completely understand how tagged template works 😝. Solved by removing .joins(db.raw`,`) part.

Thanks for such a great lib, btw

from sqlite-worker.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.