Module: Sqlyzer::Serializer
- Includes:
- Container, Parameter::Types::Alias, Sqlyzer::Sql::Request
- Included in:
- Associate::Link
- Defined in:
- lib/sqlyzer/serializer.rb
Overview
Permit to any Ruby object to be serialized on unserialized to an automatically generated Sql table through following methods :
-
sql_new,
-
sql_load,
-
sql_save,
-
sql_dispose.
Defined Under Namespace
Modules: Serializer_Class
Constant Summary
Constants included from Parameter::Types::Alias
Parameter::Types::Alias::SQL_BOOL, Parameter::Types::Alias::SQL_DATE, Parameter::Types::Alias::SQL_DATETIME, Parameter::Types::Alias::SQL_FLOAT, Parameter::Types::Alias::SQL_FLOAT4, Parameter::Types::Alias::SQL_FLOAT8, Parameter::Types::Alias::SQL_INT, Parameter::Types::Alias::SQL_INT2, Parameter::Types::Alias::SQL_INT4, Parameter::Types::Alias::SQL_INT8, Parameter::Types::Alias::SQL_TEXT, Parameter::Types::Alias::SQL_TIME, Parameter::Types::Alias::SQL_VARCHAR
Class Method Summary collapse
Instance Method Summary collapse
-
#sql_dispose ⇒ Object
Delete the object from associated table through a DELETE command.
-
#sql_load ⇒ Object
Load the object from associated table through a SELECT command.
-
#sql_new ⇒ Object
Try to load the object from associated table through a SELECT command.
-
#sql_save ⇒ Object
Try to update the object on associated table through an UPDATE command.
-
#sql_serialize(action) ⇒ Object
(also: #to_sql)
Request generation of action Sql request for current object.
Methods included from Sqlyzer::Sql::Create
#sql_alter_table, #sql_alter_table_fk, #sql_alter_table_pk, #sql_create_table, #sql_create_table_index, #sql_create_table_unique_index, #sql_drop_table
Methods included from Container
#sql_container_keys, #sql_container_table, #sql_container_values, sql_has_keys, sql_has_values, sql_set_table
Class Method Details
.included(klass) ⇒ Object
192 193 194 195 |
# File 'lib/sqlyzer/serializer.rb', line 192 def included(klass) super klass.__send__(:extend, Serializer_Class) end |
Instance Method Details
#sql_dispose ⇒ Object
Delete the object from associated table through a DELETE command.
See Sqlyzer::Request.
103 104 105 |
# File 'lib/sqlyzer/serializer.rb', line 103 def sql_dispose Handler::request self, :sql_delete end |
#sql_load ⇒ Object
Load the object from associated table through a SELECT command.
See Sqlyzer::Request.
77 78 79 |
# File 'lib/sqlyzer/serializer.rb', line 77 def sql_load Handler::request self, :sql_select end |
#sql_new ⇒ Object
Try to load the object from associated table through a SELECT command. If command failed, insert a new row in the table through an INSERT command.
See Sqlyzer::Request.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sqlyzer/serializer.rb', line 61 def sql_new begin Handler::request self, :sql_select rescue Sqlyzer::RequestError Handler::request self, :sql_insert false else true end end |
#sql_save ⇒ Object
Try to update the object on associated table through an UPDATE command. If command failed, insert a new row in the table through an INSERT command.
See Sqlyzer::Request.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sqlyzer/serializer.rb', line 87 def sql_save begin Handler::request self, :sql_update rescue Sqlyzer::RequestError Handler::request self, :sql_insert false else true end end |
#sql_serialize(action) ⇒ Object Also known as: to_sql
Request generation of action Sql request for current object.
44 45 46 47 48 49 50 |
# File 'lib/sqlyzer/serializer.rb', line 44 def sql_serialize(action) method(action).call( sql_container_table, sql_container_keys, sql_container_values ) end |