nano-store 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.gitmodules +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +193 -0
- data/Rakefile +1 -0
- data/app/app_delegate.rb +5 -0
- data/lib/nano-store.rb +1 -0
- data/lib/nano_store/bag.rb +98 -0
- data/lib/nano_store/model.rb +142 -0
- data/lib/nano_store/nano_store.rb +36 -0
- data/lib/nano_store/store_extension.rb +150 -0
- data/lib/nano_store/version.rb +3 -0
- data/lib/nano_store.rb +14 -0
- data/nano-store.gemspec +17 -0
- data/resources/.gitignore +0 -0
- data/spec/bag_spec.rb +66 -0
- data/spec/model_spec.rb +130 -0
- data/spec/nano_store_spec.rb +48 -0
- data/spec/store_extension_spec.rb +110 -0
- data/vendor/NanoStore/Classes/Advanced/NSFNanoEngine.h +542 -0
- data/vendor/NanoStore/Classes/Advanced/NSFNanoEngine.m +1781 -0
- data/vendor/NanoStore/Classes/Advanced/NSFNanoResult.h +137 -0
- data/vendor/NanoStore/Classes/Advanced/NSFNanoResult.m +265 -0
- data/vendor/NanoStore/Classes/Private/NSFNanoBag_Private.h +37 -0
- data/vendor/NanoStore/Classes/Private/NSFNanoEngine_Private.h +69 -0
- data/vendor/NanoStore/Classes/Private/NSFNanoExpression_Private.h +35 -0
- data/vendor/NanoStore/Classes/Private/NSFNanoGlobals_Private.h +99 -0
- data/vendor/NanoStore/Classes/Private/NSFNanoObject_Private.h +35 -0
- data/vendor/NanoStore/Classes/Private/NSFNanoPredicate_Private.h +35 -0
- data/vendor/NanoStore/Classes/Private/NSFNanoResult_Private.h +43 -0
- data/vendor/NanoStore/Classes/Private/NSFNanoSearch_Private.h +48 -0
- data/vendor/NanoStore/Classes/Private/NSFNanoStore_Private.h +57 -0
- data/vendor/NanoStore/Classes/Private/NanoStore_Private.h +37 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoBag.h +306 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoBag.m +485 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoExpression.h +125 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoExpression.m +103 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoGlobals.h +323 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoGlobals.m +145 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoObject.h +298 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoObject.m +187 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoObjectProtocol.h +119 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoPredicate.h +123 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoPredicate.m +130 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoSearch.h +381 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoSearch.m +835 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoSortDescriptor.h +124 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoSortDescriptor.m +79 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoStore.h +475 -0
- data/vendor/NanoStore/Classes/Public/NSFNanoStore.m +1375 -0
- data/vendor/NanoStore/Classes/Public/NanoStore.h +463 -0
- data/vendor/NanoStore/LICENSE +25 -0
- data/vendor/NanoStore/NanoStore.bridgesupport +1215 -0
- data/vendor/NanoStore/README.md +411 -0
- metadata +118 -0
data/nano-store.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/nano_store/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Francis Chong"]
|
6
|
+
gem.email = ["francis@ignition.hk"]
|
7
|
+
gem.description = "Wrapper for NanoStore, a lightweight schema-less key-value document database based on sqlite, for RubyMotion."
|
8
|
+
gem.summary = "Wrapper for NanoStore, a lightweight schema-less key-value document database based on sqlite, for RubyMotion."
|
9
|
+
gem.homepage = "https://github.com/siuying/NanoStoreInMotion"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "nano-store"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = NanoStore::VERSION
|
16
|
+
gem.add_dependency 'bubble-wrap', '>= 0.1.1'
|
17
|
+
end
|
File without changes
|
data/spec/bag_spec.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
describe NanoStore::Bag do
|
2
|
+
Bag = NanoStore::Bag
|
3
|
+
|
4
|
+
class Page < NanoStore::Model
|
5
|
+
attribute :text
|
6
|
+
attribute :index
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
NanoStore.shared_store = NanoStore.store
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
NanoStore.shared_store = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should add objects to bag" do
|
18
|
+
bag = Bag.bag
|
19
|
+
NanoStore.shared_store.addObject(bag, error:nil)
|
20
|
+
|
21
|
+
# use << method to add object to bag
|
22
|
+
page = Page.new
|
23
|
+
page.text = "Hello"
|
24
|
+
page.index = 1
|
25
|
+
bag << page
|
26
|
+
|
27
|
+
# use + method to add object to bag
|
28
|
+
page = Page.new
|
29
|
+
page.text = "World"
|
30
|
+
page.index = 2
|
31
|
+
bag += page
|
32
|
+
|
33
|
+
bag.unsaved.count.should.be == 2
|
34
|
+
bag.changed?.should.be.true
|
35
|
+
bag.save
|
36
|
+
|
37
|
+
bag.unsaved.count.should.be == 0
|
38
|
+
bag.saved.count.should.be == 2
|
39
|
+
bag.changed?.should.be.false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should delete object from bag" do
|
43
|
+
bag = Bag.bag
|
44
|
+
NanoStore.shared_store.addObject(bag, error:nil)
|
45
|
+
|
46
|
+
# use << method to add object to bag
|
47
|
+
page = Page.new
|
48
|
+
page.text = "Hello"
|
49
|
+
page.index = 1
|
50
|
+
bag << page
|
51
|
+
|
52
|
+
page = Page.new
|
53
|
+
page.text = "Foo Bar"
|
54
|
+
page.index = 2
|
55
|
+
bag << page
|
56
|
+
|
57
|
+
bag.save
|
58
|
+
bag.saved.count.should.be == 2
|
59
|
+
bag.delete(page)
|
60
|
+
bag.changed?.should.be.true
|
61
|
+
bag.removed.count.should.be == 1
|
62
|
+
bag.save
|
63
|
+
bag.saved.count.should.be == 1
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/spec/model_spec.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
describe NanoStore::Model do
|
2
|
+
|
3
|
+
class User < NanoStore::Model
|
4
|
+
attribute :name
|
5
|
+
attribute :age
|
6
|
+
attribute :created_at
|
7
|
+
end
|
8
|
+
|
9
|
+
def stub_user(name, age, created_at)
|
10
|
+
user = User.new
|
11
|
+
user.name = name
|
12
|
+
user.age = age
|
13
|
+
user.created_at = created_at
|
14
|
+
user
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
NanoStore.shared_store = NanoStore.store
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
NanoStore.shared_store = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "create object" do
|
26
|
+
user = stub_user("Bob", 10, Time.now)
|
27
|
+
user.save
|
28
|
+
|
29
|
+
user.info.keys.include?("name").should.be.true
|
30
|
+
user.info.keys.include?("age").should.be.true
|
31
|
+
user.info.keys.include?("created_at").should.be.true
|
32
|
+
|
33
|
+
user.info["name"].should == "Bob"
|
34
|
+
user.info["age"].should == 10
|
35
|
+
user.info["created_at"].should == user.created_at
|
36
|
+
|
37
|
+
user.name.should == "Bob"
|
38
|
+
user.age.should == 10
|
39
|
+
User.count.should == 1
|
40
|
+
end
|
41
|
+
|
42
|
+
it "create object with initializer" do
|
43
|
+
name = "Abby"
|
44
|
+
age = 30
|
45
|
+
created_at = Time.now
|
46
|
+
user = User.create(:name => name, :age => age, :created_at => created_at)
|
47
|
+
user.name.should == name
|
48
|
+
user.age.should == age
|
49
|
+
user.created_at.should == created_at
|
50
|
+
end
|
51
|
+
|
52
|
+
it "throw error when invalid parameter on initialize" do
|
53
|
+
lambda {
|
54
|
+
user = User.new(:name => "Eddie", :age => 12, :created_at => Time.now, :gender => "m")
|
55
|
+
}.should.raise(::NanoStore::NanoStoreError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "update objects" do
|
59
|
+
user = stub_user("Bob", 10, Time.now)
|
60
|
+
user.save
|
61
|
+
|
62
|
+
user1 = User.find(:name, NSFEqualTo, "Bob").first
|
63
|
+
user1.name = "Dom"
|
64
|
+
user1.save
|
65
|
+
|
66
|
+
user2 = User.find(:name, NSFEqualTo, "Dom").first
|
67
|
+
user2.key.should == user.key
|
68
|
+
end
|
69
|
+
|
70
|
+
it "find object" do
|
71
|
+
user = stub_user("Bob", 10, Time.now)
|
72
|
+
user.save
|
73
|
+
|
74
|
+
users = User.find(:name, NSFEqualTo, "Bob")
|
75
|
+
users.should.not.be.nil
|
76
|
+
users.count.should == 1
|
77
|
+
users.first.name.should == user.name
|
78
|
+
|
79
|
+
users = User.find_keys(:name, NSFEqualTo, "Bob")
|
80
|
+
users.should.not.be.nil
|
81
|
+
users.count.should == 1
|
82
|
+
users.first.should == user.key
|
83
|
+
end
|
84
|
+
|
85
|
+
it "delete object" do
|
86
|
+
user = stub_user("Bob", 10, Time.now)
|
87
|
+
user.save
|
88
|
+
|
89
|
+
users = User.find(:name, NSFEqualTo, "Bob")
|
90
|
+
users.should.not.be.nil
|
91
|
+
users.count.should == 1
|
92
|
+
|
93
|
+
user.delete
|
94
|
+
users = User.find(:name, NSFEqualTo, "Bob")
|
95
|
+
users.should.not.be.nil
|
96
|
+
users.count.should == 0
|
97
|
+
User.count.should == 0
|
98
|
+
end
|
99
|
+
|
100
|
+
it "find all objects" do
|
101
|
+
user = stub_user("Bob", 10, Time.now)
|
102
|
+
user.save
|
103
|
+
|
104
|
+
user2 = stub_user("Amy", 11, Time.now)
|
105
|
+
user2.save
|
106
|
+
|
107
|
+
|
108
|
+
User.count.should == 2
|
109
|
+
users = User.all
|
110
|
+
users.size.should == 2
|
111
|
+
users.collect(&:key).include?(user.key)
|
112
|
+
users.collect(&:key).include?(user2.key)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "search object" do
|
116
|
+
user = stub_user("Bob", 10, Time.now)
|
117
|
+
user.save
|
118
|
+
|
119
|
+
user2 = stub_user("Amy", 11, Time.now)
|
120
|
+
user2.save
|
121
|
+
|
122
|
+
User.count.should == 2
|
123
|
+
users = User.find(:name, NSFEqualTo, "Bob")
|
124
|
+
users.should.not.be.nil
|
125
|
+
user = users.first
|
126
|
+
user.should.not.be.nil
|
127
|
+
user.name.should.be == "Bob"
|
128
|
+
user.age.should.be == 10
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
describe NanoStore do
|
2
|
+
class Spaceship < NanoStore::Model
|
3
|
+
attribute :name
|
4
|
+
end
|
5
|
+
|
6
|
+
it "create :memory store" do
|
7
|
+
store = NanoStore.store
|
8
|
+
store.filePath.should == ":memory:"
|
9
|
+
|
10
|
+
store = NanoStore.store :memory
|
11
|
+
store.filePath.should == ":memory:"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "create :persistent store" do
|
15
|
+
path = documents_path + "/nano.db"
|
16
|
+
store = NanoStore.store :persistent, path
|
17
|
+
store.filePath.should == path
|
18
|
+
|
19
|
+
path = documents_path + "/nano.db"
|
20
|
+
store = NanoStore.store :file, path
|
21
|
+
store.filePath.should == path
|
22
|
+
end
|
23
|
+
|
24
|
+
it "create :temp store" do
|
25
|
+
store = NanoStore.store :temp
|
26
|
+
store.filePath.should == ""
|
27
|
+
|
28
|
+
store = NanoStore.store :temporary
|
29
|
+
store.filePath.should == ""
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should use shared_store if a model has no store defined" do
|
33
|
+
NanoStore.shared_store = NanoStore.store
|
34
|
+
Spaceship.store.should.not.be.nil
|
35
|
+
NanoStore.shared_store.should.not.be.nil
|
36
|
+
Spaceship.store.should == NanoStore.shared_store
|
37
|
+
|
38
|
+
Spaceship.store = NanoStore.store :temp
|
39
|
+
Spaceship.store.should.not == NanoStore.shared_store
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should enable and disable debug mode" do
|
43
|
+
NanoStore.debug = true
|
44
|
+
NanoStore.shared_store = NanoStore.store
|
45
|
+
NanoStore.debug = false
|
46
|
+
NanoStore.shared_store.should.not.be.nil
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
describe "StoreExtension" do
|
2
|
+
before do
|
3
|
+
NanoStore.shared_store = NanoStore.store
|
4
|
+
end
|
5
|
+
|
6
|
+
after do
|
7
|
+
NanoStore.shared_store = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
class Animal < NanoStore::Model
|
11
|
+
attribute :name
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should open and close store" do
|
15
|
+
NanoStore.shared_store.open
|
16
|
+
NanoStore.shared_store.closed?.should.be.false
|
17
|
+
|
18
|
+
NanoStore.shared_store.close
|
19
|
+
NanoStore.shared_store.closed?.should.be.true
|
20
|
+
|
21
|
+
NanoStore.shared_store.open
|
22
|
+
NanoStore.shared_store.closed?.should.be.false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should add, delete objects and count them" do
|
26
|
+
store = NanoStore.shared_store
|
27
|
+
|
28
|
+
obj1 = Animal.new
|
29
|
+
obj1.name = "Cat"
|
30
|
+
obj2 = Animal.new
|
31
|
+
obj2.name = "Dog"
|
32
|
+
obj3 = Animal.new
|
33
|
+
obj3.name = "Cow"
|
34
|
+
obj4 = Animal.new
|
35
|
+
obj4.name = "Duck"
|
36
|
+
|
37
|
+
store << obj1
|
38
|
+
store << [obj2, obj3]
|
39
|
+
store += obj4
|
40
|
+
|
41
|
+
store.save
|
42
|
+
Animal.count.should == 4
|
43
|
+
|
44
|
+
store.delete(obj1)
|
45
|
+
Animal.count.should == 3
|
46
|
+
|
47
|
+
store.delete_keys([obj2.key])
|
48
|
+
Animal.count.should == 2
|
49
|
+
|
50
|
+
store.clear
|
51
|
+
Animal.count.should == 0
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should discard unsave changes" do
|
55
|
+
store = NanoStore.shared_store = NanoStore.store
|
56
|
+
store.save_interval = 1000 # must use save_interval= to set auto save interval first
|
57
|
+
store.engine.synchronousMode = SynchronousModeFull
|
58
|
+
|
59
|
+
Animal.count.should == 0
|
60
|
+
obj1 = Animal.new
|
61
|
+
obj1.name = "Cat"
|
62
|
+
obj2 = Animal.new
|
63
|
+
obj2.name = "Dog"
|
64
|
+
|
65
|
+
store << [obj1, obj2]
|
66
|
+
store.changed?.should.be.true
|
67
|
+
store.discard
|
68
|
+
store.changed?.should.be.false
|
69
|
+
Animal.count.should == 0
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should create a transaction and commit" do
|
73
|
+
store = NanoStore.shared_store = NanoStore.store
|
74
|
+
store.transaction do |the_store|
|
75
|
+
Animal.count.should == 0
|
76
|
+
obj1 = Animal.new
|
77
|
+
obj1.name = "Cat"
|
78
|
+
obj1.save
|
79
|
+
|
80
|
+
obj2 = Animal.new
|
81
|
+
obj2.name = "Dog"
|
82
|
+
obj2.save
|
83
|
+
Animal.count.should == 2
|
84
|
+
end
|
85
|
+
store.save
|
86
|
+
Animal.count.should == 2
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should create a transaction and rollback when fail" do
|
90
|
+
store = NanoStore.shared_store = NanoStore.store
|
91
|
+
begin
|
92
|
+
store.transaction do |the_store|
|
93
|
+
Animal.count.should == 0
|
94
|
+
obj1 = Animal.new
|
95
|
+
obj1.name = "Cat"
|
96
|
+
obj1.save
|
97
|
+
|
98
|
+
obj2 = Animal.new
|
99
|
+
obj2.name = "Dog"
|
100
|
+
obj2.save
|
101
|
+
Animal.count.should == 2
|
102
|
+
raise "error"
|
103
|
+
end
|
104
|
+
rescue
|
105
|
+
end
|
106
|
+
store.save
|
107
|
+
Animal.count.should == 0
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|