Skip to content

Commit 8d1e7e8

Browse files
committed
Issue #1 - Support for DISTINCT, order by and limit clauses without where clause, added methods. Updated readme, examples, plugins. Changed 'persist' method to 'commit'.
1 parent 280e2c0 commit 8d1e7e8

File tree

10 files changed

+422
-499
lines changed

10 files changed

+422
-499
lines changed

README.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# jSQL
2-
v1.3
2+
v1.6
33

4-
Too often web applications rely on server side databases to store state information, causing unnecessary strain on the server and longer load time for the end user. jSQL aims to solve the quandary of the stateless web by using various APIs to store serialized data structures on the user's hard drive.
4+
jSQL is a state and data management tool as well as a robust SQL engine. For complete documentation, please see [the jSQL Wiki](https://github.com/Pamblam/jSQL/wiki).
55

66
Under the hood, jSQL has 3 layers:
77

8-
- **At the Lowest level**, jSQL automatically chooses the best method of storage to save state and interacts directly with it. This layer exposes a single method, [`jSQL.persist()`](https://github.com/Pamblam/jSQL/wiki/Persistence-Management#jsqlpersist), 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`](https://github.com/Pamblam/jSQL/wiki/Persistence-Management#jsqltables) object where the library is able to perform operations on it.
8+
- **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()`](https://github.com/Pamblam/jSQL/wiki/Persistence-Management#jsqlpersist), 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`](https://github.com/Pamblam/jSQL/wiki/Persistence-Management#jsqltables) object where the library is able to perform operations on it.
99

10-
- **In the juicy center**, a set of methods are used to build [`jSQLQuery` objects](https://github.com/Pamblam/jSQL/wiki/jSQLquery-interface) which execute CRUD commands on the jSQL database and it's tables. *(See: [`jSQL.createTable()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlcreatetableparams), [`jSQL.select()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlselectcolumns), [`jSQL.insertInto()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlinsertintotablename), [`jSQL.dropTable()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqldroptabletablename), [`jSQL.update()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlupdatetablename), and [`jSQL.deleteFrom()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqldeletefromtablename))*
10+
- **In the middle**, a set of methods are used to build [`jSQLQuery` objects](https://github.com/Pamblam/jSQL/wiki/jSQLquery-interface) which execute CRUD commands on the jSQL database and it's tables. *(See: [`jSQL.createTable()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlcreatetableparams), [`jSQL.select()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlselectcolumns), [`jSQL.insertInto()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlinsertintotablename), [`jSQL.dropTable()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqldroptabletablename), [`jSQL.update()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlupdatetablename), and [`jSQL.deleteFrom()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqldeletefromtablename))*
1111

12-
- **At the highest level**, jSQL is an SQL engine (hence the name: Javascript Query Language) which understands a subset of standard SQL passed to the [`jSQL.query()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlquerysqlquery) method, which parses a [jSQL statement](https://github.com/Pamblam/jSQL/wiki/jSQL-Syntax) and uses the above methods to create [`jSQLQuery` objects](https://github.com/Pamblam/jSQL/wiki/jSQLquery-interface) to perform operations on the database.
12+
- **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()`](https://github.com/Pamblam/jSQL/wiki/Querying-the-Database#jsqlquerysqlquery) method, which parses a [jSQL statement](https://github.com/Pamblam/jSQL/wiki/jSQL-Syntax) and uses the above methods to create [`jSQLQuery` objects](https://github.com/Pamblam/jSQL/wiki/jSQLquery-interface) to perform operations on the database.
1313

1414
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.
1515

1616
<hr>
1717

1818
## Quick Start
1919

20-
jSQL is implemented in a single JavaScript file. Save the [`jSQL.js`](https://github.com/Pamblam/jSQL/blob/master/jSQL.js) file (or if for performance junkies, the minified [`jSQL.min.js`](https://github.com/Pamblam/jSQL/blob/master/jSQL.min.js) file) to your project folder and include it.
20+
jSQL is implemented in a single JavaScript file. Save the [`jSQL.js`](https://github.com/Pamblam/jSQL/blob/master/jSQL.js) file (or the minified [`jSQL.min.js`](https://github.com/Pamblam/jSQL/blob/master/jSQL.min.js) file) to your project folder and include it.
2121

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

@@ -72,7 +72,7 @@ For more information and to read about other update, delete and other operations
7272

7373
## Documentation & Examples
7474

75-
Every aspect of jSQL is fully documented in the [jSQL Wiki](https://github.com/Pamblam/jSQL/wiki#jsql-docs), which includes [simple usage examples](https://github.com/Pamblam/jSQL/wiki/Examples) and anything else you would ever want to know about the library. The repository on GitHub also includes several more [complete and complex examples](https://github.com/Pamblam/jSQL/tree/master/examples).
75+
jSQL is fully documented in the [jSQL Wiki](https://github.com/Pamblam/jSQL/wiki#jsql-docs), which even includes more [simple usage examples](https://github.com/Pamblam/jSQL/wiki/Examples). The repository on GitHub also includes several more [complete and complex examples](https://github.com/Pamblam/jSQL/tree/master/examples).
7676

7777
<hr>
7878

@@ -86,15 +86,9 @@ Works in all major browsers, even really old ones.
8686

8787
<hr>
8888

89-
## Change Log
90-
91-
- December 11, 2016: Moved all documentation to the [Wiki Pages](https://github.com/Pamblam/jSQL/wiki#jsql-docs) as the readme was getting too long.
92-
- December 10, 2016: Implemented column typing with the release of version 1.1.
93-
94-
<hr>
95-
9689
## License & Legal
9790

9891
License info is available [here](https://github.com/Pamblam/jSQL/wiki/License).
9992

10093
<hr>
94+

examples/CRUDexample1/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
jSQL.load(function(){
156156

157157
// Uncomment this line to drop the table and start over
158-
// jSQL.query("DROP TABLE `PhoneNumbers`").execute(); jSQL.persist();
158+
// jSQL.query("DROP TABLE `PhoneNumbers`").execute(); jSQL.commit();
159159

160160
// If the table doesn't exist yet,
161161
// create it and add some sample data
@@ -165,7 +165,7 @@
165165
{ID: 1, Name: "Hillary Clinton", Phone: "(888) 812 - 8357"}
166166
];
167167
jSQL.createTable("PhoneNumbers", data).execute();
168-
jSQL.persist();
168+
jSQL.commit();
169169
}
170170

171171
// Load all the data from the database into the UI
@@ -186,7 +186,7 @@
186186
var id = lastID+1;
187187
var exe = [id, name, phone];
188188
var q = jSQL.query("INSERT INTO `PhoneNumbers` VALUES (?, ?, ?)").execute(exe);
189-
jSQL.persist();
189+
jSQL.commit();
190190
addRecordToUI(getRecordByID(id));
191191
});
192192
addEventHandler(sBtn, 'click', function(){
@@ -243,7 +243,7 @@
243243
// Delete a record by it's ID
244244
function deleteRecordByID(id){
245245
jSQL.deleteFrom('PhoneNumbers').where('ID').equals(id).execute();
246-
jSQL.persist();
246+
jSQL.commit();
247247
drawHTMLTable();
248248
}
249249

@@ -253,7 +253,7 @@
253253
var newName = prompt("Enter a new name: ",row.Name);
254254
var newPhone = prompt("Enter a new phone ",row.Phone);
255255
jSQL.query('update PhoneNumbers set Name = ?, Phone = ? where ID = ?').execute([newName,newPhone,id]);
256-
jSQL.persist();
256+
jSQL.commit();
257257
drawHTMLTable();
258258
}
259259

examples/createTables2/index.html

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,10 @@
3434
// if it does not already exist
3535
var query = jSQL.query("Create table if not exists oTable "+
3636
"(name varchar(50,5), age int, created date, greet function, favorite_hat hat)");
37-
38-
// Alternative syntax
39-
// var query = jSQL.createTable({oTable: {
40-
// name: {type:"VARCHAR"},
41-
// age: {type:"INT"},
42-
// created: {type:"DATE"},
43-
// greet: {type:"FUNCTION"},
44-
// favorite_hat: {type:"HAT"}
45-
// }}).ifNotExists();
4637

4738
// execute the query and insert the data
4839
// (if the table doesn't already exist)
49-
query.execute([{
40+
query.execute([{
5041
name: "bob",
5142
age: 27,
5243
created: new Date(),
@@ -65,7 +56,7 @@
6556
greet: function(){alert("sup dawg!");},
6657
favorite_hat: new hat("tophat","purple")
6758
}]);
68-
jSQL.persist();
59+
jSQL.commit();
6960

7061
echo("<p>There are "+jSQL.tables.oTable.data.length+" total rows in `oTable`</p>");
7162
var results = jSQL.query('SELECT * FROM `oTable`').execute().fetchAll();

examples/largeDataset2/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h1 id="loading">Loading<br><img src="./loading.gif" /></h1>
2626
if (xhttp.readyState == 4 && xhttp.status == 200) {
2727
var data = JSON.parse(xhttp.responseText);
2828
jSQL.createTable("zips", data).execute();
29-
jSQL.persist();
29+
jSQL.commit();
3030
document.getElementById('loading').style.display = "none";
3131
document.getElementById('hidden').style.display = "block";
3232
}

examples/persistence1/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
function drawButtons(){
3131
echo('<button onclick="addRecord();">Add</button>');
3232
echo('<button onclick="loadData();">Reset (to last save)</button>');
33-
echo('<button onclick="jSQL.persist();">Save</button>');
33+
echo('<button onclick="jSQL.commit();">Save</button>');
3434
// If the table exists and has records in it
3535
if(undefined !== jSQL.tables.randomStrings && jSQL.tables.randomStrings.data.length > 0){
3636
echo('<button onclick="deleteAll();">Clear</button>');

0 commit comments

Comments
 (0)