All Projects → goodybag → Mongo Sql

goodybag / Mongo Sql

An extensible SQL generation library for JavaScript with a focus on introspectibility

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mongo Sql

Synth
The Declarative Data Generator
Stars: ✭ 161 (-48.73%)
Mutual labels:  json, postgres
Algeria Cities
The list of all Algerian provinces and cities according to the official division in different formats: csv, xlsx, php, json, etc.
Stars: ✭ 232 (-26.11%)
Mutual labels:  json, sql
Web Database Analytics
Web scrapping and related analytics using Python tools
Stars: ✭ 175 (-44.27%)
Mutual labels:  json, sql
Athena Express
athena-express makes it easier to execute SQL queries on Amazon Athena by chaining together a bunch of methods in the AWS SDK. This allows you to execute SQL queries AND fetch JSON results in the same synchronous call - well suited for web applications.
Stars: ✭ 111 (-64.65%)
Mutual labels:  json, sql
Sqawk
Like Awk but with SQL and table joins
Stars: ✭ 263 (-16.24%)
Mutual labels:  json, sql
Radon
RadonDB is an open source, cloud-native MySQL database for building global, scalable cloud services
Stars: ✭ 1,584 (+404.46%)
Mutual labels:  json, sql
Octosql
OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.
Stars: ✭ 2,579 (+721.34%)
Mutual labels:  json, sql
Jl Sql
SQL for JSON and CSV streams
Stars: ✭ 44 (-85.99%)
Mutual labels:  json, sql
Ansible Role Postgresql
Ansible Role - PostgreSQL
Stars: ✭ 310 (-1.27%)
Mutual labels:  sql, postgres
Questdb
An open source SQL database designed to process time series data, faster
Stars: ✭ 7,544 (+2302.55%)
Mutual labels:  sql, postgres
Null
reasonable handling of nullable values
Stars: ✭ 1,148 (+265.61%)
Mutual labels:  json, sql
Requery
requery - modern SQL based query & persistence for Java / Kotlin / Android
Stars: ✭ 3,071 (+878.03%)
Mutual labels:  sql, postgres
Countries States Cities Database
🌍 World countries, states, regions, provinces, cities, towns in JSON, SQL, XML, PLIST, YAML, and CSV. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Timezones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency. #countries #states #cities
Stars: ✭ 1,130 (+259.87%)
Mutual labels:  json, sql
Bricks
A standard library for microservices.
Stars: ✭ 142 (-54.78%)
Mutual labels:  json, postgres
Pg variables
Session wide variables for PostgreSQL
Stars: ✭ 44 (-85.99%)
Mutual labels:  json, postgres
Bancosbrasileiros
Lista de bancos brasileiros | Brazilian banks list
Stars: ✭ 178 (-43.31%)
Mutual labels:  json, sql
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+128.34%)
Mutual labels:  json, sql
Dito
Dito.js is a declarative and modern web framework with a focus on API driven development, based on Objection.js, Koa.js and Vue.js – Released in 2018 under the MIT license, with support by Lineto.com
Stars: ✭ 44 (-85.99%)
Mutual labels:  json, sql
Il Ilce Mahalle Sokak Cadde Sql
Türkiye İl, İlçe, Mahalle, Sokak, Cadde Bilgisi SQL Şeklinde
Stars: ✭ 235 (-25.16%)
Mutual labels:  json, sql
Sq
swiss-army knife for data
Stars: ✭ 275 (-12.42%)
Mutual labels:  json, sql

MoSQL - JSON to SQL

Put value and semantic meaning back into your queries by writing your SQL as JSON:

NPM

Gitter chat

var builder = require('mongo-sql');

var usersQuery = {
  type: 'select'
, table: 'users'
, where: { $or: { id: 5, name: 'Bob' } }
};

var result = builder.sql(usersQuery);

result.values     // Array of values
result.toString() // Sql string value

Result:

select "users".* from "users" where "users.id" = $1 or "users"."name" = $2

Want to play around with the syntax? Check out the playground, documentation, and examples.

Installation:

Node.js:

npm install mongo-sql

Require.js:

jam install mongo-sql

Why JSON?

There are plenty of SQL building libraries that use a very imperative style of building SQL queries. The approach is linear and typically requires a bunch of function chaining. It removes your ability to use the query as a value and requires the library consumer to build their queries in large clumps or all at once. It's sometimes impossible with some of these libraries to reflect on the current state of the query programmatically. What columns have I added? Have I already joined against my groups table? MoSQL uses standard data structures to accomplish its query building, so you can figure out the state of the query at all times.

The reason we use standard JavaScript data structures is so everything is easily manipulated. Arrays are arrays and objects are objects. Everyone knows how to interface with them.

JSON is also a prime candidate for becoming a universally understood data representation. By using Javascript objects, we do not rule out the possibility of interoping with and porting to other languages.

It may not be as pretty as other libraries, but prettiness is not a design principle of this library. The design principles are:

Extensibility

If a feature is not supported, you should be able to add your own functionality to make it supported.

Semantic Value

The query should be represented in a manner that makes sense to developer and machine. The use of standard data structures allows the developer to use standard APIs to manipulate the query.

Examples

{
  type: 'create-table'
, table: 'jobs'
, definition: {
    id:         { type: 'serial', primaryKey: true }
  , user_id:    { type: 'int', references: { table: 'users', column: 'id' } }
  , name:       { type: 'text' }
  , createdAt:  { type: 'timestamp', default: 'now()' }
  }
}

Sorry, these are in no particular order.

For even more examples, take a look at the ./tests directory.

How does it work?

Every MoSQL query has a query type specified that maps to a SQL string template. Query types are composed of various strings and query helpers whose output maps to functions.

So type: 'select' uses the query type defined as 'select'. Every other property in the query object maps to a query helper. The 'select' query type starts off like this:

{with} select {columns} {table}...

When you have the following query:

{ type: 'select', table: 'users' }

The table property is mapped to the table query helper.

98% of the functionality in MoSQL is defined through various helper interfaces. If the functionality you need doesn't exist, you can easily register your own behavior and keep on moving along. To see how all of the functionality was implemented, just check out the helpers folder. It uses the same API as library consumers to add its functionality.

Contributing

I will happily accept pull requests. Just write a test for whatever functionality you're providing. Coding style is an evolving thing here. I'll be JSHinting this repo soon and will make the coding style consistent when I do.

Developing

Mongo-sql development is done using Gulp. If you dont have gulp installed globally, install using npm install -g gulp. Then,

  1. Install all development dependencies
npm install
  1. Watch for source/spec files & run jshint/unit-test cases for changed files
gulp watch
  1. Before committing changes, run full jshinting & unit-test cases for browserified version using default gulp target
gulp

Upgrading from 2.4.x to 2.5.x

There are two things you need to look out for:

Do not rely on adding parenthesis to strings (like in columns or returning helpers) in order to prevent MoSQL from attempting to quote the input. Instead use the expression query type:

// select something_custom - another_custom as "custom_result" from "users"
{
  type: 'select'
, table: 'users'
, columns: [
    { expression: 'something_custom - another_custom', alias: 'custom_result' }
  ]
}

If you were relying on expression objects without a type specified to be converted into a function type, this will no longer happen. Queries without types with expression specified in them will get converted to the new expression type.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].