├── .gitignore ├── Makefile ├── README.md ├── docs ├── chain_parse.txt ├── databases.txt ├── index.html ├── intro.md ├── notes.txt └── scraps.txt ├── index.js ├── lib ├── chain.js ├── drivers │ ├── couchdb.js │ ├── memory.js │ ├── mongodb.js │ └── mysql.js ├── select.js ├── selector_parser.js └── states.js ├── package.json └── test ├── core_test.js ├── memory_test.js ├── mongodb_test.js └── mysql_test.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | .DS_Store 4 | node_modules/* 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: test docs 2 | 3 | test: 4 | @node_modules/whiskey/bin/whiskey --tests "test/memory_test.js test/mongodb_test.js test/mysql_test.js test/core_test.js" 5 | 6 | testmongo: 7 | @node_modules/whiskey/bin/whiskey --tests "test/mongodb_test.js" --verbosity 2 8 | 9 | testmysql: 10 | @node_modules/whiskey/bin/whiskey --tests "test/mysql_test.js" --verbosity 2 11 | 12 | testmemory: 13 | @node_modules/whiskey/bin/whiskey --tests "test/memory_test.js" --verbosity 2 14 | 15 | docs: 16 | @dox --title select lib/select.js -i docs/intro.md > docs/index.html 17 | 18 | .PHONY: test docs 19 | .SILENT: docs 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # select 2 | 3 | `select` is a database library. 4 | 5 | Supported databases: 6 | 7 | * MySQL 8 | * MongoDB 9 | * Memory 10 | * CouchDB (partial) 11 | * Planned: PostgreSQL, SQLite 12 | * Researching: Riak, Redis, selector language 13 | 14 | ## Installation 15 | 16 | (Note that this module is not supported, and the old npm repository has been transferred to npm user zenorocha) 17 | 18 | ## Examples 19 | 20 | // Set the database connection string 21 | select.db = 'mysql://root@localhost/select-test'; 22 | 23 | // Find some items and iterate 24 | select('users') 25 | .find({ name: 'Alex' }) 26 | .limit(3) 27 | .offset(8) 28 | .each(function(index) { 29 | console.log(this); 30 | }); 31 | 32 | // Update an attribute 33 | select('users') 34 | .find(17) 35 | .attr({ name: 'Yuka' }); 36 | 37 | // Create 38 | select('users') 39 | .add({ 40 | name: 'Bob', 41 | email: 'bob@example.com' 42 | }); 43 | 44 | // Delete 45 | select('users') 46 | .find(1) 47 | .del(); 48 | 49 | // Selector language 50 | select('users[name="Alex", email="alex@example.com"]'). 51 | values(function(values) {}); 52 | 53 | ## Philosophy 54 | 55 | `select` is: 56 | 57 | * A quick way of using common database features 58 | * Easy to learn for JavaScript developers 59 | * Easy to extend 60 | 61 | `select` is not: 62 | 63 | * For building schemas 64 | * An ORM 65 | * A validation library 66 | 67 | ## License 68 | 69 | (The MIT License) 70 | 71 | Copyright (c) 2011 Alex R. Young 72 | 73 | Permission is hereby granted, free of charge, to any person obtaining 74 | a copy of this software and associated documentation files (the 75 | 'Software'), to deal in the Software without restriction, including 76 | without limitation the rights to use, copy, modify, merge, publish, 77 | distribute, sublicense, and/or sell copies of the Software, and to 78 | permit persons to whom the Software is furnished to do so, subject to 79 | the following conditions: 80 | 81 | The above copyright notice and this permission notice shall be 82 | included in all copies or substantial portions of the Software. 83 | 84 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 85 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 86 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 87 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 88 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 89 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 90 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 91 | 92 | -------------------------------------------------------------------------------- /docs/chain_parse.txt: -------------------------------------------------------------------------------- 1 | select('collection'). 2 | find(params). 3 | count(100). 4 | offset(10). 5 | (attr|del|each) => 6 | 7 | 8 | attr/del/each = execute (initiates chain parsing, then evaluates) 9 | 10 | stack => 11 | find params | 12 | count | 13 | offset | 14 | del | 15 | 16 | execution expression: del 17 | finder: params + count + offset 18 | 19 | evaluates => bulk delete for params, count offset 20 | 21 | driver: bulkDelete: 22 | SQL: DELETE FROM collection WHERE params count offset 23 | mongodb: delete based on values 24 | 25 | -------------------------------------------------------------------------------- /docs/databases.txt: -------------------------------------------------------------------------------- 1 | COUCHDB 2 | 3 | * https://github.com/creationix/couch-client 4 | * Difficulty: high 5 | * select param: design/view name 6 | * TODO: is convienient searching on a key=value possible? 7 | 8 | MONGODB 9 | 10 | * https://github.com/christkv/node-mongodb-native 11 | * Difficulty: low 12 | * select param: selector language 13 | * TODO: find all, find int/string, offset, raw 14 | 15 | MYSQL 16 | 17 | * https://github.com/felixge/node-mysql 18 | * Difficulty: low 19 | * select param: selector language 20 | * TODO: tests 21 | 22 | POSTGRES 23 | 24 | * https://github.com/brianc/node-postgres 25 | 26 | REDIS 27 | 28 | RIAK 29 | 30 | SQLITE 31 | 32 | * https://github.com/pkrumins/node-sqlite 33 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |select
Installation114 | 115 |
116 |
117 | Examples118 | 119 |
148 |
149 | Philosophy150 | 151 |
License160 | 161 |The MIT License 162 | 163 |Copyright (c) 2011 Alex R. Young | |
select | lib/select.js |
165 | 166 | |
167 |
168 |
174 | |
175 |
178 | The main
|
184 |
185 |
188 | |
189 |
192 | Set this with a database connection URI. Examples: 193 | 194 |
196 |
197 | 198 | |
199 |
200 |
201 | |
202 |
205 | Use this to change the default primary key. 206 | 207 | |
208 |
209 |
210 | |
211 |
214 | Access the underlying database library. For example, with MySQL: 215 | 216 |
218 |
219 |
220 |
221 |
|
223 |
224 |
286 | |
287 |
290 | Add a new record to the database. 291 | 292 |
294 |
295 |
296 |
297 |
|
299 |
300 |
307 | |
308 |
311 | Modify attributes. 312 | 313 |
316 |
317 |
318 |
319 |
|
321 |
322 |
342 | |
343 |
346 | Delete the current set of values, or pass a delete query to bulk delete. 347 | 348 |Delete all: 349 | 350 |
351 |
352 | Delete by ID: 353 | 354 |
355 |
356 | Delete with a query: 357 | 358 |
359 |
360 | Delete current set of values: 361 | 362 |
363 |
364 |
365 |
366 |
|
368 |
369 |
405 | |
406 |
409 | Find records. 410 | 411 |Find based on ID: 412 | select('users'). 413 | find(1, function(err, values) {}); 414 | 415 |Find based on attributes: 416 | select('users'). 417 | find({ type: 'admin' }). 418 | each(function() { console.log(this); }); 419 | 420 | 421 | 422 |
|
424 |
425 |
436 | |
437 |
440 | Limit the next database find query. 441 | ## TODO del/attr 442 | 443 | 444 | 445 |
|
447 |
448 |
452 | |
453 |
456 | Offset the next database find query. 457 | ## TODO del/attr 458 | 459 | 460 | 461 |
|
463 |
464 |
468 | |
469 |
472 | Sorts the results of the next find. 473 | ## TODO del/attr 474 | 475 |
479 |
480 |
481 |
482 |
|
484 |
485 |
489 | |
490 |
493 | Causes the previous
500 |
501 |
502 |
503 |
|
505 |
506 |
510 | |
511 |
514 | Receives all of the values for the previous operations.
515 | When a query produces an empty set,
521 |
522 |
523 |
524 |
|
526 |
527 |
534 | |
535 |
538 | Causes the current chain to execute. 539 | 540 | |
541 |
542 |
547 | |
548 |
551 | This adds a callback to run once other database operations have finished. 552 | 553 | 554 | 555 |
|
557 |
558 |
575 | |
576 |