Giter VIP home page Giter VIP logo

sequels's Introduction

Sequels

An SQL string can be built in many ways in JavaScript and other languages. Below are the variations I've seen and have used.

My personal favourite at the moment is the Concatenated array items.

Have your own way? Add it below.

Single line

var sql = 'SELECT * FROM table WHERE column = value';

Pros

  • Simple
  • Minimal typing

Cons

  • Can't grow without becoming unreadable

Multi line concatenated statements

var sql = 'SELECT * ';
sql += 'FROM table ';
sql += 'WHERE column = value ';

Or if you'd like things to line up:

var sql = '' ;
sql  = 'SELECT *' ;
sql += 'FROM table ';
sql += 'WHERE column = value ';

Pros

  • Simple(ish)
  • Can grow as needed
  • Each line is consistent

Cons

  • A space is needed on each line (beginning or end)
  • A bunch more typing for each line

Concatenated array items

var sql = [
  'SELECT *',
  'FROM table',
  'WHERE column = value'
];

Pros

  • Nice to read
  • Will grow
  • No leading/trailing space needed

Cons

  • sql.join(' ') is needed when used

Escape newline

var sql = "SELECT * \
FROM table \
WHERE column = value";

Pros

  • No extra whitespace required
  • No need for closing/opening quotes repeatedly
  • Will grow

Cons

  • Having to escape newline looks ugly

Multiline npm module

var sql = multiline(function(){/*
SELECT *
FROM table
WHERE column = value
*/});

Pros

  • Write everything as is
  • No newline escape
  • Will grow
  • No extra whitespace

Cons

  • Extra package dependency
  • Micro performance hit
  • JavaScript only (AFAIK)

sequels's People

Contributors

adrianblynch avatar johnbrett avatar

Watchers

James Cloos avatar Venkat Rangasamy avatar

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.