npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sugarcoated/fondant-sequence

v1.1.1

Published

SQL string builder.

Downloads

7

Readme

Face it, raw SQL strings are ugly. The longer one is, the uglier. Sequence attempts to solve this by implementing a chainable prototype (something that made jQuery famous) so that you can write SQL, in JavaScript, in the way it was meant to be written. This ranges from SELECT and INSERT statements, or even all JOIN types.

As it stands, Sequence has been written in an adaptable way. SQL varies throughout iterations (of which I've used MSSQL, MySQL, WebSQL & SQLite), therefore please report an issue if you encounter syntax differences that can be addressed.

API Reference

new Sequence([identifier])

Creates a new Sequence instance.

  • identifier is an optional parameter, expected as a String, that identifies the beginning of an SQL statement. When no identifier is given, it is defaulted to SELECT.

    new Sequence();
    new Sequence('CREATE')

Upon construction, you will have access to the following properties:

  • modifier is a SequencePart representing the modifier of the SQL statement. This can be SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER`, etc.
  • locator is a SequencePart representing the locator in the SQL statement. This is typically FROM or INTO.
  • condition is a SequencePart representing the condition in the SQL statement; typically a WHERE.
  • joins is a Collection containing a SequencePart for every joined table.
  • group is a SequencePart representing the grouping in the SQL statement.
  • order is a SequencePart representing the ordering in the SQL statement.
  • use is a SequencePart representing an expression generated with another Sequence instance for use with creating tables and views.
  • final is a SequencePart representing the final of the SQL statement. Currently the only possibility of a final is a LIMIT in MySQL.

.all()

Implements the * character from all SQL versions.

  new Sequence().all()
  new Sequence().distinct().all()

.distinct()

Implements the DISTINCT clause from all SQL versions.

  new Sequence().distinct()

.only(columns)

Implements the concept of specifying exact columns in a SELECT query.

  • columns is expected as a Array.<Array.<String, String, String>> representing the type of selection to perform on a specific column for a group.

    const mySequence = new Sequence() .only([

    // SQL FUNCTION, COLUMN, ALIAS
    ['COUNT', 'myColumn', 'MC'],
      

    ])

.top(amount)

Implements the TOP clause from Microsoft SQL.

  • amount is expected as a Number, representing an implication of the amount of records select in the query.

    new Sequence().top(10)

.view(name)

Implements the CREATE VIEW clause from all SQL versions.

  • name is expected as a String, representing the name of a nonexistent view.

    new Sequence('CREATE').view('myView')

.update(table)

Implements the UPDATE clause from all SQL versions.

  • table is expected as a String, representing the name of an existing table.

    new Sequence('UPDATE').update('myTable')

.from(table, [alias])

Implements the FROM clause from all SQL versions.

  • table is expected as a String, representing the name of an existing table.

  • alias is an optional parameter, expected as a String, representing the alias for that table. When no alias is given, the locator expression has no AS clause.

    new Sequence().all().from('myTable', 'MT')

.into(table, columns)

Implements the INTO clause from all SQL versions.

  • table is expected as a String, representing the name of an existing table.

  • columns is expected as an Array.<String>, representing the name of columns on that table.

    new Sequence('INSERT').into('myTable', ['myColumn'])

.where(column)

Implements the WHERE clause from all SQL versions.

  • column is expected as a String, representing a column within the table.

    new Sequence().all().from('myTable').where('myColumn') new Sequence().all().from('myTable').where('myColumn').where('myOtherColumn')

.join(type, table, [alias])

Implements the JOIN clause from all SQL versions.

  • type is expected as a String, representing the type of join. This can be INNER, OUTER, LEFT, RIGHT, or anything supported by your SQL version.

  • table is expected as a String, representing the name of an existing table.

  • alias is an optional parameter, expected as a String, representing the alias for that table. If no alias is provided, the JOIN clause has no AS appended.

    new Sequence().all().from('myTable').join('INNER', 'myOtherTable') new Sequence().all().from('myTable').join('INNER', 'myOtherTable', 'MOT')

.on(table, left_column, right_column)

Implements the ON clause from all SQL versions.

  • table is expected as a String, representing the name of the table joined to.

  • left_column is expected as a String, representing the column on the left.

  • right_column is expected as a `String, representing the column on the right.

    new Sequence() .all().from('myTable') .join('INNER', 'myOtherTable') .on('myOtherTable', 'myOtherColumn', 'myExtraColumn')

.with(sequence)

Embeds an instance of Sequence within another instance. Used for creating tables and views.

  • sequence is expected as a Sequence, representing the query to produce your view.

    new Sequence('CREATE').view('myVue').use(new Sequence().all().from('myTable'))

.groupBy(column, [ascending])

Implements the GROUP BY clause from all SQL versions.

  • column is expected as a String, representing a column to group on.

  • ascending is an optional parameter, expected as a Boolean, representing whether or not you want the results to be grouped from top to bottom or bottom to top. When no ascending is provided, the value is defaulted to false.

    new Sequence().all().from('myTable').groupBy('myColumn') new Sequence().all().from('myTable').groupBy('myColumn', true)

.orderBy(column, [ascending])

Implements the ORDER BY clause from all SQL versions.

  • column is expected as a String, representing the column to order by.

  • ascending is an optional parameter, expected as a Boolean, representing whether or not you want the results to be ordered from top to bottom or bottom to top. When no ascending is provided, the value is defaulted to false.

    new Sequence().all().from('myTable').orderBy('myColumn') new Sequence().all().from('myTable').orderBy('myColumn', true)

.limit([amount])

Implements the LIMIT clause from MySQL.

  • amount is an optional parameter, expected as a Number, representing the amount of records to limit the query to. When no amount is provided, the value defaults to 1.

    new Sequence().all().from('myTable').limit() new Sequence().all().from('myTable').limit(10)