Support
Quality
Security
License
Reuse
kandi has reviewed NanoStoreInMotion and discovered the below as its top functions. This is intended to give you an instant insight into NanoStoreInMotion implemented functionality, and help decide if they suit your requirements.
RubyMotion wrapper for NanoStore, a lightweight schema-less key-value document database based on sqlite.
Installation
gem install motion-cocoapods
pod setup
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
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
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
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
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
class Radio < NanoStore::Model
attribute :name
end
radio = Radio.new
radio.addObserver(observer, forKeyPath:"name", options: NSKeyValueObservingOptionNew, context: nil)
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
QUESTION
How to create or alter a DB schema dynamically (at run time) using Gramex FormHandler
Asked 2022-Apr-08 at 06:35I want to be able to (at run time) create or alter a DB schema dynamically on a particular event (e.g. click of a button) using FormHandler microservice of Gramex.
ANSWER
Answered 2022-Apr-08 at 06:20You can do it using queryfunction of FormHandler which can modify the query based on the query parameters passed in the url.
Refer the link below for more https://gramener.com/gramex/guide/formhandler/#formhandler-queryfunction
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit