Sha256: 0d58187a0cdea70580e930d0f248e63f803baea6a35a0a307dbd7f59b3fa9e33

Contents?: true

Size: 998 Bytes

Versions: 3

Compression:

Stored size: 998 Bytes

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
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

Swift.db do |db|
  db.migrate! User

  puts '-- create --'
  db.create(User,
    {name: 'Apple Arthurton', email: 'apple@arthurton.local'},
    {name: 'Benny Arthurton', email: 'benny@arthurton.local'}
  )

  puts '', '-- select --'
  pp users = db.prepare(User, 'select * from users').execute.to_a

  puts '', '-- update --'
  db.update(User, *users.map!{|user| user.name = 'Fred Nurk'; user})
  pp db.prepare(User, 'select * from users').execute.to_a

  puts '', '-- get --'
  pp db.get(User, id: 1)

  puts '', '-- destroy --'
  pp db.destroy(User, id: 1)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
swift-0.4.3 examples/db.rb
swift-0.4.2 examples/db.rb
swift-0.4.1 examples/db.rb