Sha256: c565649e0bf0e21c5c04a39a0b44350d6795df937c8803d357f77d507acd1a77
Contents?: true
Size: 1.16 KB
Versions: 3
Compression:
Stored size: 1.16 KB
Contents
#!/usr/bin/env ruby require_relative '../lib/swift' require 'pp' class User < Swift::Scheme store :users attribute :id, Swift::Type::Integer, serial: true, key: true attribute :name, Swift::Type::String attribute :email, Swift::Type::String attribute :active, Swift::Type::Boolean attribute :created, Swift::Type::Time, default: proc { Time.now } attribute :optional, Swift::Type::String, default: 'woot' end # User adapter = ARGV.first =~ /mysql/i ? Swift::DB::Mysql : Swift::DB::Postgres puts "Using DB: #{adapter}" Swift.setup :default, adapter, db: 'swift' Swift.trace true puts '-- migrate! --' User.migrate! puts '', '-- create --' User.create name: 'Apple Arthurton', email: 'apple@arthurton.local' User.create name: 'Benny Arthurton', email: 'benny@arthurton.local' puts '', '-- all --' pp User.all.to_a # pp User.all(':name like ?', '%Arthurton').to_a puts '', '-- first --' pp User.first(':name like ?', '%Arthurton') puts '', '-- get --' pp user = User.get(id: 2) pp user = User.get(id: 2) puts '', '-- update --' user.update(name: 'Jimmy Arthurton') puts '', '-- destroy --' user.destroy puts '', '-- all --' pp User.all.to_a
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
swift-0.4.3 | examples/scheme.rb |
swift-0.4.2 | examples/scheme.rb |
swift-0.4.1 | examples/scheme.rb |