Git Product home page Git Product logo

jsql's Introduction

jSQL Logo

jSQL (Official) - Version 3.3.19 - Now available without a prescription!

npm version Build Status Inline docs Coverage Status


jSQL is a state and data management tool as well as a robust SQL engine for both Node and the browser. For complete documentation, please see the jSQL Wiki. For plugins, live demos and other information see the official website.

jSQL Layers

Under the hood, jSQL has 3 layers...

  • At the Lowest level, jSQL automatically chooses the best method of storage to save state and interacts directly with it. This layer exposes a persistence method, jSQL.commit(), which is called to serialize and store all data currently in the jSQL database on the user's hard drive. While the app is open and loaded in the browser, this data is serialized and stored within reach in the jSQL.tables object where the library is able to perform operations on it.

  • In the middle, a set of methods are used to build jSQLQuery objects which execute CRUD commands on the jSQL database and it's tables. (See: jSQL.createTable(), jSQL.select(), jSQL.insertInto(), jSQL.dropTable(), jSQL.update(), and jSQL.deleteFrom())

  • At the highest level, jSQL is an SQL engine (hence the name: Javascript Query Language) which understands a subset of MySQL passed to the jSQL.query() method, which parses a jSQL statement and uses the above methods to create jSQLQuery objects to perform operations on the database.

jSQL is written with flexibility, ease of use, and efficiency in mind. It supports prepared statements, column typing, and can store any kind of data you need it to, including functions and instances of custom objects. It's applications include caching server-sourced data, state persistence, data management and querying and more.


Quick Start

jSQL is implemented in a single JavaScript file. You only need either the jSQL.js file or the minified jSQL.min.js file. Feel free to download them directly or use npm:

npm install jsql-official

If you're running jSQL in a browser, include it in a script tag.

<script src='jSQL.js'></script>

Or use the one hosted on the github.io site:

http://pamblam.github.io/jSQL/scripts/jSQL.min.js

If you're running jSQL in Node, require the jSQL module.

var jSQL = require("jSQL.js");

Create a table

When the database has loaded into memory, you'll want to make sure you have a table to work with. Any database operations that are to be made immediately when the app loads should be called from within the jSQL.load() callback.

jSQL.load(function(){
    var sql = "create table if not exists users (name varchar(25), age int)";
    jSQL.query(sql).execute();
});

Insert into table

At some point, you might want to put some data in that table.

jSQL.query("insert into users ('bob', 34)").execute();

Prefer prepared statements? Just replace values with question marks and pass the values to the execute method in an array.

jSQL.query("insert into users (?, ?)").execute(['bob', 34]);

Select from table

Once you've got the data in there, you're probably going to want to get it back out.

var users = jSQL.query("select * from users where name like '%ob'").execute().fetchAll("ASSOC");

Persisting changes in the browser

When you've made changes or additions to the database, call jSQL.commit() to commit your changes.

For more information and to read about other update, delete and other operations, see the jSQL Wiki.


Documentation & Examples

jSQL is fully documented in the jSQL Wiki, which even includes more simple usage examples. You may also refer to the package's tests for more complete and complex examples. There is also a live demo available on the official website.


Browser Support

Works in basically all browsers. jSQL degrades gracefully because it falls back on cookies for persistence if localStorage, IndexedDB and WebSQL are not available.

While jSQL will work in basically all browsers, these ones are preferred:

FireFox Android Safari Chrome Samsung Blackberry IE Opera Edge
2+ 2.1+ 3.1+ 4+ 4+ 7+ 8+ 11.5+ 12+

It's Official

In the same way Fedex is Federal.


Thanks to


πŸ‡ΊπŸ‡Έ

jsql's People

Contributors

outofgamut avatar pamblam 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsql's Issues

[Question] Standardization code

Interesting idea & implementation. But not complete if there is no standardization of our code. It's for the quality of our code. Therefore we need to add Javascript Standard rules with eslint-config-standard or standard JS (https://standardjs.com/)

updating pks

if you have a table with a pk and update a row to have the same pk it says pk violated... make sure pk row isn't same as updated row before throwing that error///

Readme graphics

Anyone wanna make a graphic for the jSQL readme and get an easy PR for Hacktoberfest?

Specifically, a visual representation of the 3 layers described in the top of the readme:

Under the hood, jSQL has 3 layers:

  • At the Lowest level, jSQL automatically chooses the best method of storage to save state and interacts directly with it. This layer exposes a persistence method, jSQL.commit(), which is called to serialize and store all data currently in the jSQL database on the user's hard drive. While the app is open and loaded in the browser, this data is serialized and stored within reach in the jSQL.tables object where the library is able to perform operations on it.

  • In the middle, a set of methods are used to build jSQLQuery objects which execute CRUD commands on the jSQL database and it's tables. (See: jSQL.createTable(), jSQL.select(), jSQL.insertInto(), jSQL.dropTable(), jSQL.update(), and jSQL.deleteFrom())

  • At the highest level, jSQL is an SQL engine (hence the name: Javascript Query Language) which understands a subset of MySQL passed to the jSQL.query() method, which parses a jSQL statement and uses the above methods to create jSQLQuery objects to perform operations on the database.

You can upload it to imgur and put it in the readme, above the section quoted above.

inserting questionmarks

If you comment off the conditional it works..

<html>
	<body>
		<div id="myDiv">Loading...</div>
		<script src="//cdn.rawgit.com/Pamblam/jSQL/master/jSQL.js"></script>
		<script>
			jSQL.load(function(){
                jSQL.query("create table if not exists certificates ("+
                    "sponsorid varchar, sponsorname varchar, "+
                    "address varchar, city varchar, state varchar, "+
                    "state varchar, zip varchar, primaryphone varchar, frontgraphic varchar, "+
                    "backgraphic varchar, request_id int, offer_desc varchar)").execute();
              
                  var params = ["pop", "Bob's Carpet Mart", "123 main st", "Clearwater", "FL", 34683, "(813) 500-8221", "110981", null, "14574", "Free Large 2 Topping Pizza"];
                  var selectSQL = "select * from certificates where sponsorid = ? and sponsorname = ? and address = ? and city = ? and state = ? and zip = ? and primaryphone = ? and frontgraphic = ? and request_id = ? and offer_desc = ?";
                  var insertSQL = "insert into certificates (sponsorid, sponsorname, address, city, state, zip, primaryphone, frontgraphic, backgraphic, request_id, offer_desc) values (?,?,?,?,?,?,?,?,?,?,?)";

                  // only insert the record if it does not already exist
                  if(!jSQL.query(selectSQL).execute(params).fetch('ARRAY').length)
                    jSQL.query(insertSQL).execute(params);
              
              	  var certs = jSQL.query("select * from certificates").execute().fetchAll();
              
              	  console.log(certs);
            });
		</script>
	</body>
</html>

columns mismatch

inserting breaks when using column names:

create table poops (color varchar(20), stink int)
insert into poops (color, stink) values ("red", 7)

also,

execute() should be chainable on insert queries as well, even though there is nothing to fetch.

Is there ability to make JOIN operation?

Hey @Pamblam nice job! Have couple questions, please take a look when you are be able to:

  • Do you plan add API methods to support JOIN operations?
  • Is there ability to use JOIN within .query() method?

Thanks!

Todo list #1

  • Ensure all query types escape backticks on column names
  • Support for "LIMIT", "ORDER BY" on queries that don't have a where clause
  • Support for DISTINCT/DISTINCTROW and ALL keywords

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.