Module: ChefFixie::Sql
- Defined in:
- lib/chef_fixie_shahid/sql.rb,
lib/chef_fixie_shahid/sql_objects.rb
Defined Under Namespace
Modules: Relationships Classes: Associations, Client, Clients, Container, Containers, Cookbook, CookbookArtifact, CookbookArtifacts, Cookbooks, DataBag, DataBags, Environment, Environments, Group, Groups, InvalidConfig, Invites, Node, Nodes, Org, Orgs, Policies, Policy, PolicyGroup, PolicyGroups, Role, Roles, SqlObject, SqlTable, User, Users
Class Method Summary collapse
-
.connection_string ⇒ Object
Returns the connection string or raises an error if you didn’t set one.
-
.connection_string=(sequel_connection_string) ⇒ Object
A connection string passed to Sequel.connect().
-
.default_connection ⇒ Object
Returns a Sequel::Data baseobject, which wraps access to the database.
Instance Method Summary collapse
-
#as_json(data) ⇒ Object
Encode the portion of the object that’s stored as a blob o’ JSON.
-
#from_json(serialized_data) ⇒ Object
Parse the portion of the object that’s stored as a blob o’ JSON.
-
#new_uuid ⇒ Object
Generate a new UUID.
Class Method Details
.connection_string ⇒ Object
Returns the connection string or raises an error if you didn’t set one.
48 49 50 |
# 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) ⇒ Object
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
41 42 43 44 45 |
# 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 ⇒ Object
Returns a Sequel::Data baseobject, which wraps access to the database.
53 54 55 56 |
# 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 |
Instance Method Details
#as_json(data) ⇒ Object
Encode the portion of the object that’s stored as a blob o’ JSON
69 70 71 |
# File 'lib/chef_fixie_shahid/sql.rb', line 69 def as_json(data) FFI_Yajl::Encoder.encode(data) end |
#from_json(serialized_data) ⇒ Object
Parse the portion of the object that’s stored as a blob o’ JSON
64 65 66 |
# 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 ⇒ Object
Generate a new UUID. Currently uses the v1 UUID scheme.
59 60 61 |
# File 'lib/chef_fixie_shahid/sql.rb', line 59 def new_uuid UUIDTools::UUID..hexdigest end |