Class: Amalgalite::Function
- Inherits:
-
Object
- Object
- Amalgalite::Function
- Defined in:
- lib/amalgalite/function.rb
Overview
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
Instance Attribute Summary collapse
-
#arity ⇒ Object
The arity of the SQL function.
-
#name ⇒ Object
The name of the SQL function.
Instance Method Summary collapse
-
#initialize(name, arity) ⇒ Function
constructor
Initialize the function with a name and arity.
-
#signature ⇒ Object
Do Not Override.
-
#to_proc ⇒ Object
All SQL functions defined foloow the
to_proc
protocol.
Constructor Details
#initialize(name, arity) ⇒ Function
Initialize the function with a name and arity
42 43 44 45 |
# File 'lib/amalgalite/function.rb', line 42 def initialize( name, arity ) @name = name @arity = arity end |
Instance Attribute Details
#arity ⇒ Object
The arity of the SQL function
39 40 41 |
# File 'lib/amalgalite/function.rb', line 39 def arity @arity end |
#name ⇒ Object
The name of the SQL function
36 37 38 |
# File 'lib/amalgalite/function.rb', line 36 def name @name end |
Instance Method Details
#signature ⇒ Object
Do Not Override
The function signature for use by the Amaglaite datase in tracking function definition and removal.
57 58 59 |
# File 'lib/amalgalite/function.rb', line 57 def signature @signature ||= ::Amalgalite::SQLite3::Database::Function.signature( self.name, self.arity ) end |
#to_proc ⇒ Object
All SQL functions defined foloow the to_proc
protocol
48 49 50 |
# File 'lib/amalgalite/function.rb', line 48 def to_proc self end |