Coder Social home page Coder Social logo

Comments (7)

GregoryPotdevin avatar GregoryPotdevin commented on May 16, 2024

I had the same idea a few days ago and thought it would need a babel preprocessor...
Would love to have this !

from node-sqlite.

wmertens avatar wmertens commented on May 16, 2024

In the meantime you can use

export const S = (strings, ...values) => [strings.join('?'), values]
db.all(...S`select * from foo where t = ${bar}`).then(...)

But the proposed approach is of course better. Would also be nice to have an id escape mechanism, since you can't pass e.g. table names as parameters. Options: either inline SELECT * FROM id${tableName} or through magic objects SELECT * FROM ${id(tableName)}. I think I prefer inline.

from node-sqlite.

tracker1 avatar tracker1 commented on May 16, 2024

@wmertens, would be better to use String objects for enhanced strings...

db.literal = str => Object.assign(new String(str), { literal: true });

then check for a .literal property on a String...

if (str intanceof String && str.literal)

But that would be more than a simple join, of course.

from node-sqlite.

wmertens avatar wmertens commented on May 16, 2024

True. More obvious, but more typing though ☺

from node-sqlite.

tracker1 avatar tracker1 commented on May 16, 2024
var id = db.literal;
...
db.all(`...  ${id(someTableName)} ...`)

Not too bad...

from node-sqlite.

theogravity avatar theogravity commented on May 16, 2024

Create a PR w/ unit tests and an updated readme on usage

from node-sqlite.

tracker1 avatar tracker1 commented on May 16, 2024

Will see if I can work on this soon... haven't been working with sqlite lately, so will need to create some test scenarios and get it working.

from node-sqlite.

Related Issues (20)

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.