GithubHelp home page GithubHelp logo

siuying / nanostoreinmotion Goto Github PK

View Code? Open in Web Editor NEW
103.0 8.0 24.0 906 KB

RubyMotion wrapper for NanoStore, a lightweight schema-less key-value document database based on sqlite.

License: Other

Ruby 100.00%

nanostoreinmotion's Introduction

NanoStore for RubyMotion

Wrapper for NanoStore, a lightweight schema-less key-value document database based on sqlite, in RubyMotion.

Status: Work in progress. API subject to change.

Find a sample application using NanoStore here

How to use Blog here

Installation

Install the CocoaPods dependency manager if you haven't it already:

gem install motion-cocoapods
pod setup

Install nano-store gem

gem install nano-store

Require nano-store to your project 'Rakefile'

$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require 'rubygems'
require 'motion-cocoapods'
require 'nano-store'

Motion::Project::App.setup do |app|
  app.name = 'myapp'
  
  # Add the pod NanoStore to your project
  app.pods do
    pod 'NanoStore', '~> 2.6.0'
  end
end

Now, you can use NanoStore in your app.

Upgrade Notes

If you are upgrading from an older version of nano-store gem, make sure you run rake clean and remove vendor/Pods/build* folders before building your project. Otherwise you may still using the old binaries!

Basic Usage

Set default storage type

# memory only db
NanoStore.shared_store = NanoStore.store(:memory)

# file based db
documents_path         = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
NanoStore.shared_store = NanoStore.store(:file, documents_path + "/nano.db")

Define Model

class User < NanoStore::Model
  attribute :name
  attribute :age
  attribute :created_at
end

A key (UUID) that identifies the object will be added automatically.

Attributes must be serializable, which means that only the following data types are allowed:

  • NSArray
  • NSDictionary
  • NSString
  • NSData (*)
  • NSDate
  • NSNumber
  • NSNull
  • NSURL

Note

(*) The data type NSData is allowed, but it will be excluded from the indexing process.

Create

# Initialize a new object and save it
user = User.new(:name => "Bob", :age => 16, :created_at => Time.now)
user.save
user.key # => "550e8400-e29b-41d4-a716-446655440000" (automatically generated UUID)

# Create a new object directly
user = User.create(:name => "Bob", :age => 16, :created_at => Time.now)

Retrieve

# find all models
User.all # => [<User#1>, <User#2>]

# find model by criteria
users = User.find(:name, NSFEqualTo, "Bob")

# or use Hash
users = User.find(:name => "Bob")
users = User.find(:name => { NSFEqualTo => "Ronald" })
users = User.find(:name => { NSFEqualTo => "Ronald" }, :age => { NSFGreaterThan => 50 })

# or use Array for matching multiple values
users = User.find(:name => ["Bob", "Ronald", "Ken"])

# Optionally sort the result with additional hash parameters
users = User.find({:age => { NSFGreaterThan => 10 }}, {:sort => {:age => :desc}})

Update

user = User.find(:name, NSFEqualTo, "Bob").first
user.name = "Dom"
user.save

Delete

user = User.find(:name, NSFEqualTo, "Bob").first
user.delete

# Bulk delete
User.delete(:age => {NSFGreaterThan => 20})

Using Transaction

Use transaction is easy, just wrap your database code in a transaction block.

store = NanoStore.shared_store = NanoStore.store

begin
  store.transaction do |the_store|
    Animal.count # => 0
    obj1 = Animal.new
    obj1.name = "Cat"
    obj1.save
      
    obj2 = Animal.new
    obj2.name = "Dog"
    obj2.save
    Animal.count # => 2
    raise "error"  # => an error happened!
  end
rescue
  # error handling
end

Animal.count # => 0

Using Bags

A bag is a loose collection of objects stored in a document store.

store = NanoStore.store
bag = Bag.bag
store << bag

# add subclass of NanoStore::Model object to bag
page = Page.new
page.text = "Hello"
page.index = 1
bag << page 
    
# save the bag
bag.save
  
# obtain the bags from document store
bags = store.bags

Association

Use bag to declare a Bag that associated with a Model.

class User < NanoStore::Model
  attribute :name
  attribute :age
  attribute :created_at
  bag :cars
end

class Car < NanoStore::Model
  attribute :name
  attribute :age
end

user = User.new(:name => "Peter", :age => 20, :created_at => Time.now)
user.cars << Car.new(:name => "Mini", :age => 0)
user.save

user.cars # => #<NanoStore::Bag:0x7411410> 

KVO

If you are using NanoStoreInMotion with KVO, aware that NanoStore::Model actually store data in a field info and create methods dynamically. Instead of listening on the field name field_name, you should listen on key path info.field_name.

For example, instead of following code:

class Radio < NanoStore::Model
  attribute :name
end

radio = Radio.new
radio.addObserver(observer, forKeyPath:"name", options: NSKeyValueObservingOptionNew, context: nil)

You should do:

radio = Radio.new
radio.addObserver(observer, forKeyPath:"info.name", options: NSKeyValueObservingOptionNew, context: nil)

Performance Tips

NanoStore by defaults saves every object to disk one by one. To speed up inserts and edited objects, increase NSFNanoStore's saveInterval property.

Example

# Create a store
store = NanoStore.shared_store = NanoStore.store
    
# Increase the save interval
store.save_interval = 1000

# Do a bunch of inserts and/or edits
obj1 = Animal.new
obj1.name = "Cat"
store << obj1

obj2 = Animal.new
obj2.name = "Dog"
store << obj2

# Don't forget that some objects could be lingering in memory. Force a save.
store.save

Note: If you set the saveInterval value to anything other one, keep in mind that some objects may still be left unsaved after being added or modified. To make sure they're saved properly, call:

store.save

Choosing a good saveInterval value is more art than science. While testing NanoStore using a medium-sized dictionary (iTunes MP3 dictionary) setting saveInterval to 1000 resulted in the best performance. You may want to test with different numbers and fine-tune it for your data set.

Credit

  • Based on NanoStore from Tito Ciuro, Webbo, L.L.C.

License

BSD License

nanostoreinmotion's People

Contributors

siuying avatar jaimeiniesta avatar tchukuchuk avatar gouravtiwari avatar defvol avatar simonpang avatar tmeinlschmidt avatar ankit8898 avatar

Stargazers

Angus H. avatar skywalker avatar Thomas Witt avatar Weto Olaguer avatar Bent Bruun avatar Evgeny Erohin avatar M. Scott Ford avatar Tri Vuong avatar Willian van der Velde avatar Liu Lantao avatar kyohei tsukuda avatar Nattaphoom Chaipreecha avatar Bill Gloff avatar Sam Chueng avatar Jaune Carlo Sarmiento avatar Manuel Boy avatar Shinn avatar  avatar Stefan Vermaas avatar Daniel Inkpen avatar ssw avatar Nathan Rivera avatar Bruno Alano avatar  avatar Andrew Gertig avatar Karl Larsaeus avatar Jem avatar Shuhei KONDO avatar Kelvin Pompey avatar Dmitriy Plekhanov avatar Luke Matthew Sutton avatar  avatar Holger Sindbaek avatar Ryusuke Sekiguchi avatar Tim Neems avatar chitsung.lin avatar Cristiano Betta avatar Chris Edwards avatar Íker Karam avatar Jonathan Yu avatar Rupak Ganguly avatar skywalker avatar Yeeland Chen avatar Kenrick Chien  avatar Muescha avatar Andrew Weir avatar Guillermo Iguaran avatar Lin He avatar Anthony Powles avatar Kareem Kouddous avatar Matt Aimonetti avatar  avatar  avatar Alessandro Berbenni avatar James Tang avatar  avatar Nick Cernis avatar Stephan Toggweiler avatar  avatar  avatar Keith Turner avatar Yaoquan avatar Matt Garrison avatar Naoya Makino avatar Pavel Kotlyar avatar Minku Lee avatar Brian Erling avatar Chris Polk avatar  avatar Florian Bertholin avatar Matt Green avatar Jan Weinkauff avatar Berklee avatar Douglas Puchalski avatar Richard Venneman avatar Robert Beene avatar yohei sugigami avatar Thomas Shelton avatar Imran Ansari avatar Sean Gaffney avatar  avatar Federico Feroldi avatar Matthew Lanham avatar Gurpartap Singh avatar Moski Doski avatar Sebastian avatar Kyle Bragger avatar Eiji Iwazawa avatar Julias Shaw avatar Matthew Abbott avatar Fabio Kuhn avatar Rainux Luo avatar Chinseok Lee avatar Nelson Yee avatar Ideamonk avatar Brent Hargrave avatar Ben Damman avatar Masakuni Kato avatar Alistair Holt avatar Arun Agrawal avatar

Watchers

 avatar Qi He avatar toshiaki okano avatar Liu Lantao avatar James Cloos avatar  avatar  avatar  avatar

nanostoreinmotion's Issues

How to sort without params

Hello,

How can I sort a query without params?
This does not work (sorting is not working):

Project.all({:sort => {:created_at => :desc}})

Nor this:

Project.find({:sort => {:created_at => :desc}})

This works however I have no param to include. I just want to get all records and sort them:

Project.find({:project => @project },{:sort => {:created_at => :desc}})

Save after update is not persisted.

Hello,

When I save record and then tries to update it I get no errors but it is not persisted.

tasks = Task.find(:id, NSFEqualTo, task).first
tasks.track_time = "end"
tasks.save

If I check p.track_time I get the correct value. But if I for example
does this in Repl or other place in the app I get the original value and not the changed value.

tasks = Task.find(:id, NSFEqualTo, task).first
tasks.track_time => start

Getting Error while running Rake

i am using nanostore in my rubymotion app.
i have installed all the thing mentioned in README file
ruby version is ruby-1.9.3-p194 and motion 1.6
but when i am running rake command i am getting the following error -:

/Library/RubyMotion/lib/motion/project.rb:16: warning: Insecure world writable dir /usr/local in PATH, mode 040777
     Build ./build/iPhoneSimulator-5.1-Development
     Build vendor/Pods
Build settings from command line:
    ARCHS = i386
    CONFIGURATION_BUILD_DIR = build
    SDKROOT = iphonesimulator5.1

=== BUILD NATIVE TARGET Pods OF PROJECT Pods WITH CONFIGURATION Release ===
Check dependencies

ProcessPCH /var/folders/p8/ylt13v016xj6m4tntc01kn3m0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dvzstflxmctdrlaplrliflxextnz/Pods-prefix.pch.pth Pods-prefix.pch normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/rashmiyadav/mprojects/raffler/vendor/Pods
    setenv LANG en_US.US-ASCII
    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/rashmiyadav/.rvm/gems/ruby-1.9.3-p194/bin:/Users/rashmiyadav/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/rashmiyadav/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/rashmiyadav/.rvm/bin:/usr/local/bin:/Users/rashmiyadav/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/oracle/instantclient_10_2"
    /usr/bin/gcc-4.2 -x objective-c-header -arch i386 -fmessage-length=0 -std=gnu99 -Wno-trigraphs -fpascal-strings -Os -Wno-missing-field-initializers -Wmissing-prototypes -Wreturn-type -Wno-implicit-atomic-properties -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-sign-compare -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -fexceptions -fasm-blocks -Wprotocol -Wdeprecated-declarations -mmacosx-version-min=10.6 -g -Wno-conversion -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300 -I/Users/rashmiyadav/mprojects/raffler/vendor/Pods/build/Pods.build/Release-iphonesimulator/Pods.build/Pods.hmap -I/Users/rashmiyadav/mprojects/raffler/vendor/Pods/build/include -I/Users/rashmiyadav/mprojects/raffler/vendor/Pods/Headers -I/Users/rashmiyadav/mprojects/raffler/vendor/Pods/Headers/NanoStore -I/Users/rashmiyadav/mprojects/raffler/vendor/Pods/build/Pods.build/Release-iphonesimulator/Pods.build/DerivedSources/i386 -I/Users/rashmiyadav/mprojects/raffler/vendor/Pods/build/Pods.build/Release-iphonesimulator/Pods.build/DerivedSources -F/Users/rashmiyadav/mprojects/raffler/vendor/Pods/build -fobjc-arc --serialize-diagnostics /var/folders/p8/ylt13v016xj6m4tntc01kn3m0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dvzstflxmctdrlaplrliflxextnz/Pods-prefix.pch.dia -c /Users/rashmiyadav/mprojects/raffler/vendor/Pods/Pods-prefix.pch -o /var/folders/p8/ylt13v016xj6m4tntc01kn3m0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dvzstflxmctdrlaplrliflxextnz/Pods-prefix.pch.pth -MMD -MT dependencies -MF /var/folders/p8/ylt13v016xj6m4tntc01kn3m0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dvzstflxmctdrlaplrliflxextnz/Pods-prefix.pch.d
2012-05-23 15:35:12.739 xcodebuild[10188:4c03]  DVTAssertions: Warning in /SourceCache/IDEXcode3ProjectSupport/IDEXcode3ProjectSupport-1197/Xcode3Sources/XcodeIDE/Frameworks/DevToolsBase/pbxcore/SpecificationTypes/XCCommandLineToolSpecification.m:817
Details:  Unable to get message category info for tool '/usr/bin/gcc-4.2'.
Reason: i686-apple-darwin11-gcc-4.2.1: no input files

Object:   <XCCompilerSpecificationClang: 0x4009b37e0>
Method:   -messageCategoryInfoForExecutablePath:
Thread:   <NSThread: 0x4010b0020>{name = (null), num = 4}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
i686-apple-darwin11-gcc-4.2.1: /var/folders/p8/ylt13v016xj6m4tntc01kn3m0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dvzstflxmctdrlaplrliflxextnz/Pods-prefix.pch.dia: No such file or directory
cc1obj: error: unrecognized command line option "-Wno-implicit-atomic-properties"
cc1obj: error: unrecognized command line option "-Wno-deprecated-implementations"
cc1obj: error: unrecognized command line option "-Wno-sign-conversion"
cc1obj: error: unrecognized command line option "-fobjc-arc"
cc1obj: error: unrecognized command line option "-fserialize-diagnostics"
Command /usr/bin/gcc-4.2 failed with exit code 1


** BUILD FAILED **


The following build commands failed:
    ProcessPCH /var/folders/p8/ylt13v016xj6m4tntc01kn3m0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dvzstflxmctdrlaplrliflxextnz/Pods-prefix.pch.pth Pods-prefix.pch normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
rake aborted!
Command failed with status (65): [/usr/bin/xcodebuild -project "Pods.xcodepr...]

Tasks: TOP => default => simulator => build:simulator
(See full trace by running task with --trace)

Error when launching

I'm having trouble launching the app after adding the gem to my bundle. I always get this error:

*** Terminating app due to uncaught exception 'NameError', reason: 'undefined method `discardUnsavedChanges' for class `NSFNanoStore' (NameError)

I'm targeting iOS 5.1 with RubyMotion 1.25.

uninitialized constant NSFLessThan

Hello,
Some NanoStore finder options(NSFLessThan, NSFBeforeDate..) doesn't seem to work.

(main)> ar = Article.find(:is_checked => {NSFGreaterThan => 0})
=> [#<Article:0x1028e740>, #<Article:0x1028b780>]


(main)> ar = Article.find(:is_checked => {NSFLessThan => 1})
=> #<NameError: uninitialized constant NSFLessThan>

(main)> ar = Article.find(:created_at => {NSFBeforeDate => Time.now})
=> #<NameError: uninitialized constant NSFBeforeDate>

Have you any suggestions ?
Thanks.

Rails ActiveRecord conventions

Curious how you might feel about some pull requests to converge more toward established conventions, i.e. obj#attributes rather than obj#info, save returning true/false, etc.

Find returns no records

Hi,
I have a model with Latitude and Longitude fields. I am trying to find records by Latitude or Longitude but find does not return any results even though the record exists.
Example:
@user_location = UserLocation.find(:latitude => 37.33233141).first

Can anyone offer some advice?

Thanks,
Neil

Add callbacks

Would it be possible to implement callbacks ie: before_save, after_save, etc?

NSFEqualTo syntax

Any plans on making this more ruby-ish, at least for equivalence?

User.find(:name => "Joe")

The squeel gem has an even better syntax for different matchers in case you haven't seen it.

Getting error when running rake

First of all thanks for the application. Nice work..

Not sure why I am getting this error while running rake.

any help is appreciated.

     Build ./build/iPhoneSimulator-5.0-Development
     Build vendor/Pods
Build settings from command line:
    ARCHS = i386
    CONFIGURATION_BUILD_DIR = build
    SDKROOT = iphonesimulator5.0

=== BUILD NATIVE TARGET Pods OF PROJECT Pods WITH CONFIGURATION Release ===
Check dependencies

ProcessPCH /var/folders/28/yc3j5vsx3d186tpqltt30npc0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dzqxvoievrsbejclccpeoppgvvsj/Pods-prefix.pch.pth Pods-prefix.pch normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/arunagw/motion/NanoStoreInMotion/vendor/Pods
    setenv LANG en_US.US-ASCII
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/Users/arunagw/.rvm/gems/ruby-1.9.3-p194@motion/bin:/Users/arunagw/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/arunagw/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/arunagw/.rvm/bin:/usr/local/bin:/Users/arunagw/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/oracle/instantclient_10_2"
    /usr/bin/gcc-4.2 -x objective-c-header -arch i386 -fmessage-length=0 -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -std=gnu99 -Wno-trigraphs -fpascal-strings -Os -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -fexceptions -fasm-blocks -mmacosx-version-min=10.6 -gdwarf-2 -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300 -I/Users/arunagw/motion/NanoStoreInMotion/vendor/Pods/build/Pods.build/Release-iphonesimulator/Pods.build/Pods.hmap -I/Users/arunagw/motion/NanoStoreInMotion/vendor/Pods/build/include -I/Users/arunagw/motion/NanoStoreInMotion/vendor/Pods/Headers -I/Users/arunagw/motion/NanoStoreInMotion/vendor/Pods/Headers/NanoStore -I/Users/arunagw/motion/NanoStoreInMotion/vendor/Pods/build/Pods.build/Release-iphonesimulator/Pods.build/DerivedSources/i386 -I/Users/arunagw/motion/NanoStoreInMotion/vendor/Pods/build/Pods.build/Release-iphonesimulator/Pods.build/DerivedSources -F/Users/arunagw/motion/NanoStoreInMotion/vendor/Pods/build -fobjc-arc -c /Users/arunagw/motion/NanoStoreInMotion/vendor/Pods/Pods-prefix.pch -o /var/folders/28/yc3j5vsx3d186tpqltt30npc0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dzqxvoievrsbejclccpeoppgvvsj/Pods-prefix.pch.pth -MMD -MT dependencies -MF /var/folders/28/yc3j5vsx3d186tpqltt30npc0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dzqxvoievrsbejclccpeoppgvvsj/Pods-prefix.pch.d
2012-05-29 12:42:43.893 xcodebuild[29695:3603]  DVTAssertions: Warning in /SourceCache/IDEXcode3ProjectSupport/IDEXcode3ProjectSupport-934/Xcode3Sources/XcodeIDE/Frameworks/DevToolsBase/pbxcore/SpecificationTypes/XCCommandLineToolSpecification.m:828
Details:  Unable to get message category info for tool '/usr/bin/gcc-4.2'.
Reason: i686-apple-darwin11-gcc-4.2.1: no input files

Object:   <XCCompilerSpecificationClang: 0x401087fc0>
Method:   -messageCategoryInfoForExecutablePath:
Thread:   <NSThread: 0x4013f4660>{name = (null), num = 6}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
cc1obj: error: unrecognized command line option "-Wno-sign-conversion"
cc1obj: error: unrecognized command line option "-fdiagnostics-print-source-range-info"
cc1obj: error: unrecognized command line option "-fdiagnostics-show-category=id"
cc1obj: error: unrecognized command line option "-fdiagnostics-parseable-fixits"
cc1obj: error: unrecognized command line option "-fobjc-arc"
Command /usr/bin/gcc-4.2 failed with exit code 1


** BUILD FAILED **


The following build commands failed:
    ProcessPCH /var/folders/28/yc3j5vsx3d186tpqltt30npc0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Pods-prefix-dzqxvoievrsbejclccpeoppgvvsj/Pods-prefix.pch.pth Pods-prefix.pch normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
rake aborted!
Command failed with status (65): [/usr/bin/xcodebuild -project "Pods.xcodepr...]

Tasks: TOP => default => simulator => build:simulator

Where and how to setup default storage type?

I'm following the instructions on the README, but when it comes to "Set default storage type", I'm a bit lost...

Where should this be done? I mean, in what file? app_delegate? Rakefile? An initializer?

Also, the line with "documents_path" will fail if it's not defined in the project.

Could you provide a more detailed example about this? Maybe you have a demo app?

Thanks! :)

Can't add bag to store

I can't make Bag to work. Seems it can save to sqlite but can't get back the objects. I can't pass this case:

  it "should add bag to store" do

    before_count = NanoStore.shared_store.bags.count

    bag = Bag.bag
    NanoStore.shared_store.addObject(bag, error:nil)

    # use << method to add object to bag
    page = Page.new
    page.text = "Hello"
    page.index = 1
    bag << page 

    bag.save
    NanoStore.shared_store.save   #PS: is this needed?

    NanoStore.shared_store.bags.count.should.be == before_count + 1
  end

crashes running with `rake target=4.3`

When I execute with rake target=4.3, application crashes and puts messages below in terminal.
(It's ok when I run rake target=5.1.)

$ rake target=4.3
     Build ./build/iPhoneSimulator-4.3-Development
     Build vendor/Pods
  Simulate ./build/iPhoneSimulator-4.3-Development/NanoStoreSandbox.app
dyld: lazy symbol binding failed: Symbol not found: _objc_retain
  Referenced from: /Users/satoshi/Library/Application Support/iPhone Simulator/4.3.2/Applications/A534A999-AB0C-4712-AAA6-C7214A240734/NanoStoreSandbox.app/NanoStoreSandbox
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/libobjc.A.dylib

dyld: Symbol not found: _objc_retain
  Referenced from: /Users/satoshi/Library/Application Support/iPhone Simulator/4.3.2/Applications/A534A999-AB0C-4712-AAA6-C7214A240734/NanoStoreSandbox.app/NanoStoreSandbox
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/libobjc.A.dylib

((null))> rake aborted!
Command failed with status (1): [DYLD_FRAMEWORK_PATH="/Applications/Xcode.a...]

Tasks: TOP => default => simulator
(See full trace by running task with --trace)

My Rakefile is here.

# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'

require 'bundler/setup'
Bundler.require :default

Motion::Project::App.setup do |app|
  # Use `rake config' to see complete project settings.
  app.name = 'NanoStoreSandbox'
  app.deployment_target = '4.3'
  app.pods do
    pod 'NanoStore'
  end
end

and app/app_delegate.rb is here.

class Memo < NanoStore::Model
  attribute :body
end

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)

    NanoStore.shared_store = NanoStore.store(:file, App.documents_path + "/nano.db")
    Memo.create(:body => 'foobarbaz')

    true
  end
end

uninitialized constant error

uninitialized constant NanoStore::Model::AssociationInstanceMethods (NameError)
Terminating app due to uncaught exception 'NameError', reason: 'uninitialized constant NanoStore::Model::AssociationInstanceMethods (NameError)

Occurs in empty application that just has

require 'nano-store'

and

pod 'NanoStore'

in Rakefile

nano-store works perfectly fine with 0.4.3. It occurs only with 0.5.1

Single quotes not escaped properly in .find

Nice work! We're running into an issue, though, where it appears that single quotes aren't being escaped properly when passed to Model.find.

   Model.find(name: "I don't work properly")

throws an error that ultimately results in a SQLite error code 1.

   Model.find(name: "I don''t work properly")

Works properly, note the second single quote escaping the first.

Ui blocks on create methods

I'm using the nanodb with ruby motion to store data locally.
As you use the app, remote services are called once in a while, data saved in the db.

It does grow with time (as any db would do), but for a thousand entries the app got quite stuck on the ui side while creating models. Surprisingly, the finds queries are pretty stable.

I would be glad to get some feedback on what's happening, if you see something right here
best

Getting object by key

Hi

I don't see how I can get objects by key. In fact I would like to use NanoStore with relationships, for example :

class Player < NanoStore::Model
  attribute :name
  attribute :created_at
end

class Game < NanoStore::Model
  attribute :name
end

class Participation < NanoStore::Model
  attribute :player_key
  attribute :game_key

  def player
    Player.find(:key => player_key).first
  end

  def game
    Game.find(:key => game_key).first
  end
end

player = Player.new(:name => 'julien')
player.save
game = Game.new(:name => 'game')
game.save
participation = Participation.new(:player_key => player.key, :game_key => game.key)
participation.save
participation.player # returns nil
participation.game # returns nil

The other way is to write something like this, but it may not be efficient :

class Participation
  def player
     Player.all.each { |pl| return pl if pl.key == player_key }
     nil
  end
end

Have you any suggestions ?

Best regards,

Julien

Finders are not working

Whenever i try to search/find for something, the app crashes with the following error:

LLVM ERROR: Program used external function 'rb_pointer_new2' which could not be resolved!

User.find(:name => 'moski')

where to define storage type

Hi,

i am not sure where i have to define my storage type in my app??

could you please help me ?

thanks in advance

Undefined symbols for architecture i386

Undefined symbols for architecture i386:
"_NSFSetIsDebugOn", referenced from:
_MREP_95211FC97BA34C5FA92C2C43067D0E4A in nano_store.rb.o

I am getting this error.
I remember it was reported but dont remember what resolved the issue.

[OSX] Undefined symbols for architecture i386: _NSFSetIsDebugOn

I have the same as #17, it only occurs when I build for release:

> rake build:release COCOAPODS_VERBOSE=1                                                                                                                                                               master [7f83c31] (!) deleted untracked
bubble-wrap/camera requires iOS to use.
bubble-wrap/ui requires iOS to use.

Finding Podfile changes
  - NanoStore

Resolving dependencies of

Resolving dependencies for target `Pods' (OS X 10.8)
  - NanoStore (= 2.7.7)
  - NanoStore (= 2.7.7)

Comparing resolved specification to the sandbox manifest
  - NanoStore
     Build ./build/MacOSX-10.8-Release
     Build vendor/Pods
   Compile ./app/models/activity_group.rb
   Compile ./app/config/constants.rb
   Compile ./app/config/version.rb
   Compile ./app/models/activity_event.rb
   Compile ./app/models/notification_center.rb
   Compile ./app/services/notification_tracker.rb
   Compile ./app/views/status_bar_menu.rb
   Compile ./app/controllers/main_window_controller.rb
   Compile ./app/app_delegate.rb
   Compile ./app/extensions/app.rb
   Compile ./app/extensions/time.rb
   Compile ./app/views/main_menu.rb
    Create ./build/MacOSX-10.8-Release/Timi.app/Contents
    Create ./build/MacOSX-10.8-Release/Timi.app/Contents/MacOS
      Link ./build/MacOSX-10.8-Release/Timi.app/Contents/MacOS/Timi
ld: warning: ignoring file /Users/jankeesvw/Documents/timi/timi-osx/vendor/Pods/build-MacOSX/libPods.a, file was built for archive which is not the architecture being linked (i386): /Users/jankeesvw/Documents/timi/timi-osx/vendor/Pods/build-MacOSX/libPods.a
Undefined symbols for architecture i386:
  "_NSFSetIsDebugOn", referenced from:
      _MREP_735B065C4474420FAA8A0248EC143EC7 in nano_store.rb.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
rake aborted!
Command failed with status (1): [/usr/bin/clang++ -o "./build/MacOSX-10.8-R...]
/Library/RubyMotion/lib/motion/project/builder.rb:299:in `build'
/Library/RubyMotion/lib/motion/project/app.rb:76:in `build'
/Library/RubyMotion/lib/motion/project/template/osx.rb:46:in `block (2 levels) in <top (required)>'
Tasks: TOP => build:release
(See full trace by running task with --trace)

This is my Gemfile:

source 'https://rubygems.org'

gem 'rake'
gem 'bubble-wrap'
gem 'nano-store', :git => '[email protected]:jankeesvw/NanoStoreInMotion.git'
gem 'motion-cocoapods'

And my Rakefile:

# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/osx'

begin
  require 'bundler'
  Bundler.require
rescue LoadError
end

require 'motion-cocoapods'
require 'bubble-wrap/core'
require 'nano-store'

require File.expand_path("../app/config/version.rb", __FILE__)

Motion::Project::App.setup do |app|
  app.pods do
    pod 'NanoStore', '2.7.7'
  end

  app.name = 'Timi'
  app.version = APP_VERSION
  app.frameworks += ['WebKit', 'AppKit']
  app.icon = 'icon.icns'
end

Is there any way to create a relationship with a bag and StoreNano::Model

how can we create an instance of NanoStore::Model with one bag associated with it?
from the example below, we want to create a User has one bag which contains instances of Car. Is this possible?

 class Car < NanoStore::Model
    attribute :name
    attribute :age
  end

  class User < NanoStore::Model
    attribute :name
    attribute :age
    attribute :created_at
    attribute :cars #we want this to be a link to a bag.
  end

Version conflict

If I use this setup in my Rakefile

require 'bundler'
Bundler.require

Motion::Project::App.setup do |app|

  app.pods do
    pod 'NanoStore', '~> 2.5.7'
  end

end

I get following error when running rake

Podfile tries to activate `NanoStore (~> 2.5.7)', but already activated version `2.5.2' by Podfile.

Since I'm using bundler I have gem 'nano-store' in my Gemfile.

Therefore when I run Bundler.require in my Rakefile nano_store is required and app.pods.pod 'NanoStore', '2.5.2' is executed. Source: nano_store.rb

I think the version of the pod should be decided by the user and not hard coded.

REPL

I have no idea if this is a problem in the pod, the gem, Rubymotion itself, or my system setup... But I guess it's better asking than not.

I can use methods like find absolutely fine in actual code, but if I try using it in the REPL I get this error and the whole app crashes:

(main)> User.find(a: 1)
dyld: lazy symbol binding failed: Symbol not found: __ZN9RoxorCore14find_bs_cftypeESs
  Referenced from: /Library/RubyMotion/data/ios/7.0/iPhoneSimulator/libmacruby-repl.dylib
  Expected in: flat namespace

dyld: Symbol not found: __ZN9RoxorCore14find_bs_cftypeESs
  Referenced from: /Library/RubyMotion/data/ios/7.0/iPhoneSimulator/libmacruby-repl.dylib
  Expected in: flat namespace

doesn't really make any difference which arguments are given as long as they're in an expected format.

Any ideas?

Getting Error while running Rake

Hi,I am trying to run your rake on my machine.

but i am getting error.

The following build commands failed:
    CompileC build/Pods.build/Release-iphonesimulator/Pods.build/Objects-normal/i386/NSFNanoBag.o NanoStore/Classes/Public/NSFNanoBag.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    CompileC build/Pods.build/Release-iphonesimulator/Pods.build/Objects-normal/i386/NSFNanoSearch.o NanoStore/Classes/Public/NSFNanoSearch.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler

i think it might be because i have 64 -bit mac.do you have any idea about it..how can i resolve it?

find not returning anything

I have a few different models and for some reason my Listing model will not return anything when I do a Listing.all.

Listing.count shows 0.

However if I look in the db file, it looks like the RBListing is there fine with all the values.

KVO on attributes in NanoStore::Model

Hey,

I haven't been able to get KVO working using attributes defined on a NanoStore::Model.

If I replace the attribute with an attr_accessor KVO starts working so I don't think I'm doing anything wrong initializing the KVO. EG:

# attribute :disliked # KVO doesn't register
attr_accessor :disliked # KVO works

Any idea how it is possible to fix this? My code would be much cleaner if I were able to use KVO on my model attributes.

nano-store version is 0.6.0

Let me know if you need any further information.

Thanks

save on the store doesn't seem to have any effect

I may not quite understand how saving works. It seems that the only way to get objects saved to the database is to save each one using the save method on the object instead of delaying the save and calling the save method on the store. Replacing "user.save" in this code with "NanoStore.shared_store.save" breaks this case.

describe NanoStore::Model do

 class User < NanoStore::Model
    attribute :name
    attribute :age
    attribute :created_at
  end

  def stub_user(name, age, created_at)
    user = User.new
    user.name = name
    user.age  = age
    user.created_at = created_at
    user
  end

  before do
    NanoStore.shared_store = NanoStore.store
  end

  after do
    NanoStore.shared_store = nil
  end

  it "saving via the store instead of model" do

    user = stub_user("Bob", 10, Time.now)

    user.save
#NanoStore.shared_store.save

    user.info.keys.include?("name").should.be.true
    user.info.keys.include?("age").should.be.true
    user.info.keys.include?("created_at").should.be.true

    user.info["name"].should == "Bob"
    user.info["age"].should == 10
    user.info["created_at"].should == user.created_at

    User.count.should == 1
  end

end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.