Skip to content

Commit

Permalink
Added a dump function
Browse files Browse the repository at this point in the history
  • Loading branch information
guyroyse committed Nov 2, 2010
1 parent e3664b8 commit 77cb8a2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
65 changes: 26 additions & 39 deletions sample-queries.txt
Original file line number Diff line number Diff line change
@@ -1,65 +1,52 @@
Database Operations
-------------------

Save objects: proton.db('things').save(<object>)
proton.db('things').save(<object>,<object>,<object>...)
Save objects: proton.db('things').save(<object>)
proton.db('things').save(<object>,<object>,<object>...)
Remove matching objects: proton.db('things').remove(<query>)
proton.db('things').remove(<query>,<query>,<query>...)
Remove all objects: proton.db('things').clear()
proton.db('things').remove(<query>,<query>,<query>...)
Remove all objects: proton.db('things').clear()
Update matching objects: proton.db('things').update(<update>,<query>)
proton.db('things').update(<update>,<query>,<query>,<query>...)
proton.db('things').update(<update>,<query>,<query>,<query>...)
Query matching objects: <array> proton.db('things').find(<query>)
<array> proton.db('things').find(<query>,<query>,<query>...)
Get all objects: <array> proton.db('things').all()
<array> proton.db('things').find(<query>,<query>,<query>...)
Get all objects: <array> proton.db('things').all()
Get distinct objects: <array> proton.db('things').distinct()
Match objects: <bool> proton.match(<object>, <query>)
Match objects: <bool> proton.match(<object>, <query>)

A sample <object>: {name:'Alex Trabeck', occupation:'Game Show Host', favorites:{bird:'robin', color:'blue'}}
A sample <object>: {name:'Alex Trabeck', occupation:'Game Show Host', favorites:{bird:'robin', color:'blue'}}
A sample <query>:
(simple) {occupation: 'Game Show Host'}
(stock function) {salary: proton.greaterThan(100000)}
(custom function) {occupation: function(value) { return value.charAt(3) == 'e' } }
(complex) {occupation: 'Game Show Host', salary: proton.greaterThan(100000)}
(regex) {occupation: /Game/)
(deep) (name: 'Alex Trabeck', favorites: {color: 'blue'} }
A sample <update>:i
(add) {salary: 250000}
(remove) {occupation: undefined}
(change) {occupation: 'Spokesman'}
A sample <sort>: {occupation: proton.ascending, salary: proton.descending}
(simple) {occupation: 'Game Show Host'}
(stock function) {salary: proton.greaterThan(100000)}
(custom function) {occupation: function(value) { return value.charAt(3) == 'e' } }
(complex) {occupation: 'Game Show Host', salary: proton.greaterThan(100000)}
(regex) {occupation: /Game/)
(deep) (name: 'Alex Trabeck', favorites: {color: 'blue'} }
A sample <update>:
(add) {salary: 250000}
(remove) {occupation: undefined}
(change) {occupation: 'Spokesman'}
A sample <sort>: {occupation: proton.ascending, salary: proton.descending}

Some ideas:
Array Operations
----------------

Constructor:
(empty) new Array()
(copy) new Array('foo','bar','baz')
(empty) new Array()
(copy) new Array('foo','bar','baz')
Filter array: <array> things.sift(<query>)
First set of items: <array> things.top(5)
Last set of items: <array> things.bottom(3)
Paged items: <array> things.page(2,20)
First object <object> things.first()
Last object: <object> things.last()
Distinct items: <array> Array.distinct()
Sort array: <array> Array.order(<sort>)
Sort array: <array> Array.order(<sort>)

Complex queries: <array> proton.db('things').all().distinct().sift(<query>).order(<sort>).top()

=============================================================================================================

Future Features
Meta Operations
---------------

Meta Stuff:
List of sets: <array> proton.sets()
returns a list of all set names

Dump: <array> proton.dump()
dumps contents of entire database into an array of arrays


Other Ideas
-----------
Array Matches -- matches array values
Random sorting
Dump all sets: <list> proton.dump()
Clear all sets: proton.wipe()
14 changes: 14 additions & 0 deletions spec/unit/proton.db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ describe 'proton'
proton.sets().should.be_empty
end
end

describe '.dump()'
it 'should return entire database when dumped'
var dump = proton.dump()
dump['data'].length.should.be 3
dump['data'][0].foo.should.be 'foo'
dump['data'][1].foo.should.be 'bar'
dump['data'][2].foo.should.be 'baz'
dump['data2'].length.should.be 2
dump['data2'][0].baz.should.be 'baz'
dump['data2'][1].baz.should.be 'qux'

end
end

describe '.db()'
it 'should return a database when asked'
Expand Down
7 changes: 7 additions & 0 deletions src/proton.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ proton.wipe = function() {
proton.sets().forEach(function(item) {
proton.db(item).clear();
})
}
proton.dump = function() {
var data = []
proton.sets().forEach(function(item) {
data[item] = proton.db(item).all()
})
return data
}

0 comments on commit 77cb8a2

Please sign in to comment.