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

Commit 785aa66

Browse files
A bit more documentation
1 parent cbe5f42 commit 785aa66

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

README.md

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,74 @@ 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_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

1919
## API
2020

2121
__`CREATE()` - creates a new table__
22+
2223
You can define your tables by supplying a name for the table and a object-based definition (type checking is coming…).
2324

24-
>>> `DB.CREATE( 'my_first_table', { id: 0, foo: bar, test: 'ing' } );`
25+
> `DB.CREATE( 'my_first_table', { id: 0, foo: 'bar', test: 'ing' } );`
2526
26-
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 third (optional) argument.
27+
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()`).
2728

28-
>>> `DB.CREATE( 'my_first_table', {id:0,foo:bar,test:'ing'}, [{foo:'baz',test:'ed'},{foo:'bat',test:'er'}] );`
2929

30-
__`INSERT()` - adds data to a table__
30+
__`INSERT_INTO()` - adds data to a table__
3131

32-
>>> `DB.INSERT( 'my_first_table', [{foo:'baz',test:'ed'},{foo:'bat',test:'er'}] );`
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

36+
3637
__`SELECT()` - find data in a table__
38+
3739
You can select all data in a table by only supplying the table name to the method
3840

39-
>>> `DB.SELECT( 'my_first_table' );`
41+
> `DB.SELECT( 'my_first_table' ); [{id:0,foo:'bar',test:'ed'},{id:1,foo:'bat',test:'ing'}]`
4042
4143
Or you can collect a subset of rows, using an object to define your search criteria (JOIN and complex criteria are coming).
4244

43-
>>> `DB.SELECT( 'my_first_table', {foo:'bar'} );`
45+
> `DB.SELECT( 'my_first_table', {foo:'bar'} ); // [{id:0,foo:'bar',test:'ed'}]`
46+
47+
48+
__`UPDATE()` - updates rows in a table__
49+
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'}]`
53+
54+
55+
__`DELETE()` - remove data from a table__
56+
57+
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.
58+
59+
> `DB.DELETE( 'my_first_table', {foo:'bar'} );`
60+
> `DB.SELECT( 'my_first_table', {foo:'bar'} ); // []`
61+
62+
Supplying only the table name is the same as calling `TRUNCATE()`
63+
64+
65+
__`AFFECTED_ROWS()` - returns the number of rows affected by the last operation__
66+
67+
> `DB.INSERT_INTO( 'my_first_table', {test:'ed'} );`
68+
> `DB.AFFECTED_ROWS(); // 1
69+
70+
__`TRUNCATE()` - empty a table & reset its index, but retain its definition__
71+
72+
> `DB.TRUNCATE( 'my_first_table' );`
73+
> `DB.SELECT( 'my_first_table' ); // []`
74+
75+
__`DESCRIBE()` - returns the definition for a table__
76+
77+
> `DB.DESCRIBE( 'my_first_table' ); // { id: 0, foo: 'bar', test: 'ing' }`
78+
79+
__`DROP()` - drop a table from the DB__
80+
81+
> `DB.DROP( 'my_first_table' );`
82+
> `DB.SELECT( 'my_first_table' ); // ERROR
4483
4584

4685
## License

0 commit comments

Comments
 (0)