module ChefFixie::Sql
Public Class Methods
connection_string()
click to toggle source
Returns the connection string or raises an error if you didn't set one.
# File lib/chef_fixie_shahid/sql.rb, line 48 def self.connection_string @connection_string ||= ChefFixie.configure { |x| x.sql_database } end
connection_string=(sequel_connection_string)
click to toggle source
A connection string passed to Sequel.connect()
Examples:
-
“mysql2://root@localhost/opscode_chef”
-
“mysql2://user:password@host/opscode_chef”
-
“jdbc:mysql://localhost/test?user=root&password=root”
See also: sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html
# File lib/chef_fixie_shahid/sql.rb, line 41 def self.connection_string=(sequel_connection_string) @database.disconnect if @database.respond_to?(:disconnect) @database = nil @connection_string = sequel_connection_string end
default_connection()
click to toggle source
Returns a Sequel::Data baseobject, which wraps access to the database.
# File lib/chef_fixie_shahid/sql.rb, line 53 def self.default_connection @database ||= Sequel.connect(connection_string, :max_connections => 2) # @database.loggers << Logger.new($stdout) end
Public Instance Methods
as_json(data)
click to toggle source
Encode the portion of the object that's stored as a blob o' JSON
# File lib/chef_fixie_shahid/sql.rb, line 69 def as_json(data) FFI_Yajl::Encoder.encode(data) end
from_json(serialized_data)
click to toggle source
Parse the portion of the object that's stored as a blob o' JSON
# File lib/chef_fixie_shahid/sql.rb, line 64 def from_json(serialized_data) FFI_Yajl::Parser.parse(serialized_data, :symbolize_keys => true) end
new_uuid()
click to toggle source
Generate a new UUID. Currently uses the v1 UUID scheme.
# File lib/chef_fixie_shahid/sql.rb, line 59 def new_uuid UUIDTools::UUID.timestamp_create.hexdigest end