Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # encoding: utf-8
- require 'sequel'
- # Database Manager Class
- # @function: Initializing and Manipulating the Models and the DB Connection.
- class DatabaseManager
- def initialize
- self.database = Sequel.mysql 'sinatra', :user => 'sryche',
- :password => '**********************', :host => 'localhost'
- end
- end
- # User Model Class
- # @function: Helps on User Management on Database.
- class Users
- def initialize(db)
- @db = db.database
- unless @db.table_exists?(:users)
- @db.create_table :users do
- primary_key :id
- String :username
- String :password
- Integer :role
- end
- end
- @users = @db[:users]
- end
- def insert(values)
- @users.insert(values)
- end
- def print_users
- p @users.count
- end
- end
- # Posts Model Class
- # @function: Helps on Post Management on Database.
- class Posts
- def initialize(db)
- @db = db
- unless @db.table_exists?(:posts)
- @db.create_table :posts do
- primary_key :id
- String :title
- String :body
- String :tags
- Integer :category_id
- Integer :user_id
- end
- end
- @users = @db[:posts]
- end
- end
Add Comment
Please, Sign In to add comment