Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit 9146aa5

Browse files
Updated docs
1 parent a8be0b6 commit 9146aa5

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

README.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The API is still developing, but using LocalStorageDB is pretty simple:
1212

1313
1. Create a new instance of the LocalStorageDB object, supplying the name you wish to give the DB
1414

15-
> `var DB = new LocalStorageDB('my_first_database');`
15+
`var DB = new LocalStorageDB('my_first_database');`
1616

1717
2. If the DB exists already (from a previous session), you're good to go. Otherwise, see the API to do the usual CRUD operations.
1818

@@ -22,14 +22,14 @@ __`CREATE()` - creates a new table__
2222

2323
You can define your tables by supplying a name for the table and a object-based definition (type checking is coming…).
2424

25-
> `DB.CREATE( 'my_first_table', { id: 0, foo: 'bar', test: 'ing' } );`
25+
`DB.CREATE( 'my_first_table', { id: 0, foo: 'bar', test: 'ing' } );`
2626

2727
If you want to load data in immediately, you can do that by supplying a single object (for one row) or an array of objects (for multiple rows) as the optional third argument (see `INSERT_INTO()`).
2828

2929

3030
__`INSERT_INTO()` - adds data to a table__
3131

32-
> `DB.INSERT_INTO( 'my_first_table', [{test:'ed'},{foo:'bat'}] );`
32+
`DB.INSERT_INTO( 'my_first_table', [{test:'ed'},{foo:'bat'}] );`
3333

3434
_Note: Any table defined to have an `id` property will automatically assign a unique auto-incremented id to that property upon insertion. Also, any defaults set in the definition object will be used if the property is not defined on the inserted object._
3535

@@ -38,48 +38,57 @@ __`SELECT()` - find data in a table__
3838

3939
You can select all data in a table by only supplying the table name to the method
4040

41-
> `DB.SELECT( 'my_first_table' ); [{id:0,foo:'bar',test:'ed'},{id:1,foo:'bat',test:'ing'}]`
41+
`DB.SELECT( 'my_first_table' ); [{id:0,foo:'bar',test:'ed'},{id:1,foo:'bat',test:'ing'}]`
4242

43-
Or you can collect a subset of rows, using an object to define your search criteria (JOIN and complex criteria are coming).
43+
Or you can collect a subset of rows, using an object to define your search criteria.
4444

45-
> `DB.SELECT( 'my_first_table', {foo:'bar'} ); // [{id:0,foo:'bar',test:'ed'}]`
45+
`DB.SELECT( 'my_first_table', {foo:'bar'} ); // [{id:0,foo:'bar',test:'ed'}]`
46+
47+
Or you can collect a subset of rows, using a function to collect rows (by returning `true`).
48+
49+
`DB.SELECT( 'my_first_table', function( row ){ return ( row.foo == 'bar' ); } ); // [{id:0,foo:'bar',test:'ed'}]`
50+
51+
`SELECT()` returns a `RESULT_SET` object (which inherits from Array). `RESULT_SET` objects can be mutated by the methods `ORDER_BY()` and `LIMIT()`.
52+
53+
`DB.SELECT( 'my_first_table' ).LIMIT(1)[0]; // {id:0,foo:'bar',test:'ed'}`
54+
`DB.SELECT( 'my_first_table' ).ORDER_BY( 'foo DESC' ).LIMIT(1)[0]; // {id:1,foo:'bat',test:'ing'}`
4655

4756

4857
__`UPDATE()` - updates rows in a table__
4958

50-
> `DB.SELECT( 'my_first_table', {foo:'bar'} ); // [{id:0,foo:'bar',test:'ed'}]`
51-
> `DB.UPDATE( 'my_first_table', {test:'nada'}, {foo:'bar'} );`
52-
> `DB.SELECT( 'my_first_table', {foo:'bar'} ); // [{id:0,foo:'bar',test:'nada'}]`
59+
`DB.SELECT( 'my_first_table', {foo:'bar'} ); // [{id:0,foo:'bar',test:'ed'}]`
60+
`DB.UPDATE( 'my_first_table', {test:'nada'}, {foo:'bar'} );`
61+
`DB.SELECT( 'my_first_table', {foo:'bar'} ); // [{id:0,foo:'bar',test:'nada'}]`
5362

5463

5564
__`DELETE()` - remove data from a table__
5665

5766
You can delete select rows from a table using (you guessed it) a criteria object. Currently, all criteria must be met for the row to be removed.
5867

59-
> `DB.DELETE( 'my_first_table', {foo:'bar'} );`
60-
> `DB.SELECT( 'my_first_table', {foo:'bar'} ); // []`
68+
`DB.DELETE( 'my_first_table', {foo:'bar'} );`
69+
`DB.SELECT( 'my_first_table', {foo:'bar'} ); // []`
6170

6271
Supplying only the table name is the same as calling `TRUNCATE()`
6372

6473

6574
__`AFFECTED_ROWS()` - returns the number of rows affected by the last operation__
6675

67-
> `DB.INSERT_INTO( 'my_first_table', {test:'ed'} );`
68-
> `DB.AFFECTED_ROWS(); // 1
76+
`DB.INSERT_INTO( 'my_first_table', {test:'ed'} );`
77+
`DB.AFFECTED_ROWS(); // 1`
6978

7079
__`TRUNCATE()` - empty a table & reset its index, but retain its definition__
7180

72-
> `DB.TRUNCATE( 'my_first_table' );`
73-
> `DB.SELECT( 'my_first_table' ); // []`
81+
`DB.TRUNCATE( 'my_first_table' );`
82+
`DB.SELECT( 'my_first_table' ); // []`
7483

7584
__`DESCRIBE()` - returns the definition for a table__
7685

77-
> `DB.DESCRIBE( 'my_first_table' ); // { id: 0, foo: 'bar', test: 'ing' }`
86+
`DB.DESCRIBE( 'my_first_table' ); // { id: 0, foo: 'bar', test: 'ing' }`
7887

7988
__`DROP()` - drop a table from the DB__
8089

81-
> `DB.DROP( 'my_first_table' );`
82-
> `DB.SELECT( 'my_first_table' ); // ERROR
90+
`DB.DROP( 'my_first_table' );`
91+
`DB.SELECT( 'my_first_table' ); // ERROR`
8392

8493

8594
## License

0 commit comments

Comments
 (0)