Class | Amalgalite::Function |
In: |
lib/amalgalite/function.rb
lib/amalgalite/function.rb |
Parent: | Object |
A Base class to inherit from for creating your own SQL scalar functions in ruby.
These are SQL functions similar to _abs(X)_, _length(X)_, _random()_. Items that take parameters and return value. They have no state between calls. Built in SQLite scalar functions are :
Functions defined in Amalgalite databases conform to the Proc interface. Everything that is defined in an Amalgalite database using define_function has its to_proc method called. As a result, any Function must also conform to the to_proc protocol.
If you choose to use Function as a parent class of your SQL scalar function implementation you should only have implement call with the appropriate arity.
For instance to implement a _sha1(X)_ SQL function you could implement it as
class SQLSha1 < ::Amalgalite::Function def initialize super( 'md5', 1 ) end def call( s ) ::Digest::MD5.hexdigest( s.to_s ) end end
arity | [RW] | The arity of the SQL function |
arity | [RW] | The arity of the SQL function |
name | [RW] | The name of the SQL function |
name | [RW] | The name of the SQL function |