Code Monkey home page Code Monkey logo

sql's People

Contributors

dependabot-preview[bot] avatar lucleray avatar yannvgn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sql's Issues

Nested sql.raw tags

const sql = require('@sequencework/sql')
console.log(sql`
  0  ${sql.raw(`
            1 ${sql.raw('2')}
  `)}
`.text)

Output :

\n  0  \n            1 [object Object]\n  \n

Expected :

\n  0  \n            1 2\n  \n

Actually, it's not really a bug, it's more a discussion.

pg-sql2

Have you seen pg-sql2? Just wondering how it compares to this lib?

Nested sql tags accross modules

I have a library which constructs SQL filters and I want to consume it in my main project.

Example

In library:

export const filter = sql`WHERE year = 2018`;

In the main project:

const {filter} = require('library');
sql`SELECT * FROM books ${filterThisYear ? filter : undefined}`

Expected behavior

I expect nested sql tags to merge and append the filter.

Actual behavior

Due to the object weirdness in JavaScript, class instances are compared by their prototype chain which depends on the way the class was imported. In this case, instanceof returns false. The SqlContainer class is the same, but imported from a different place. Finally this cause sql not to detect nested tag and treats is as an object parameter instead.

Suggested fix

I created a fork which adds a tag method to allow comparison across modules. This is not the cleanest code ever, but is successfully used in Moment.js for instance.

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.