SQLite::TypeTranslator (Class)

In: lib/rq-3.0.0/sqlite.rb
Parent: Object
TypeTranslator Database lib/rq-3.0.0/sqlite.rb SQLite Module: SQLite

The TypeTranslator is a singleton class that manages the routines that have been registered to convert particular types. The translator only manages conversions in queries (where data is coming out of the database), and not updates (where data is going into the database).

Methods

Public Class methods

Registers the given block to be used when a value of the given type needs to be translated from a string.

[Source]

     # File lib/rq-3.0.0/sqlite.rb, line 237
237:     def self.add_translator( type, &block )
238:       @@translators[ type_name( type ) ] = block
239:     end

Looks up the translator for the given type, and asks it to convert the given value.

[Source]

     # File lib/rq-3.0.0/sqlite.rb, line 243
243:     def self.translate( type, value )
244:       unless value.nil?
245:         @@translators[ type_name( type ) ].call( type, value )
246:       end
247:     end

Finds the base type name for the given type. Type names with parenthesis (like "VARCHAR(x)" and "DECIMAL(x,y)") will have the parenthesized portion removed.

[Source]

     # File lib/rq-3.0.0/sqlite.rb, line 252
252:     def self.type_name( type )
253:       type = $1 if type =~ /^(.*?)\(/
254:       type.upcase
255:     end

[Validate]