Sha256: e85509fbd1e809bbc65564a055ef6ab283dc640b40e8ea82049bb1e55100f431
Contents?: true
Size: 829 Bytes
Versions: 18
Compression:
Stored size: 829 Bytes
Contents
require_relative "user" class Baza::Driver::Mysql::Users def initialize(args) @args = args @db = @args.fetch(:db) end def list result = [] @db.query("SELECT * FROM mysql.user") do |user_data| user = Baza::Driver::Mysql::User.new( db: @db, data: user_data ) if block_given? yield user else result << user end end result unless block_given? end def find_by_name(name) list do |user| return user if user.name == name.to_s end raise Baza::Errors::UserNotFound, "Could not find a user by that name: #{name}" end def create(data) @db.query("CREATE USER '#{@db.esc(data.fetch(:name))}'@'#{@db.esc(data.fetch(:host))}' IDENTIFIED BY '#{data.fetch(:password)}'") find_by_name(data.fetch(:name)) end end
Version data entries
18 entries across 18 versions & 1 rubygems