11 from ctypes
import POINTER
12 from SQLamarr
import clib, c_TransformerPtr
13 from typing
import List
17 clib.new_Plugin.argtypes = (
27 clib.new_Plugin.restype = c_TransformerPtr
31 Wrap an external function as defined in a compiled shared library.
33 Python bindings for SQLamarr::Plugin.
35 The C function `function_name` is selected from the shared object
36 `library_path` and evaluated for each row obtained executing the
37 `query` on the database `db`. Results are stored in the temporary
38 table `output_table` whose columns are named after the list of `outputs`.
39 The columns returned by the `query`
40 are all interpreted as inputs to the external functions, unless
41 they are listed as `references`, in that case they are copied to the output
42 table, easying JOIN operations with other tables in the database.
56 Acquire the db and configure the interface with the compiled function.
59 @param db: An open database connection;
60 @param library_path: path-like string defining the library defining the
62 @param function_name: string defining the name of the function to execute;
63 @param query: SQL query defining the input and reference columns;
64 @param output_table: name of the table where reference and output are
66 @param outputs: list of the output column names for further reference;
67 @param references: list of columns selected by `query` to be used as
68 reference indices instead of passing as inputs to the external function.
72 self.
_self_self = clib.new_Plugin(
74 library_path.encode(
'ascii'),
75 function_name.encode(
'ascii'),
76 query.encode(
'ascii'),
77 output_table.encode(
'ascii'),
78 ";".join(outputs).encode(
'ascii'),
79 ";".join(references).encode(
'ascii'),
85 """@private: Release the bound class instance"""
86 clib.del_Transformer(self.
_self_self)
89 def raw_pointer(self):
90 """@private: Return the raw pointer to the algorithm."""
91 return self.
_self_self
94 """@private: Indicateds the linked symbol for error displaying."""
95 return f
"<SQLamarr.Plugin '{self._function_name}'>"
Wrap an external function as defined in a compiled shared library.
def __init__(self, SQLite3DB db, str library_path, str function_name, str query, str output_table, List[str] outputs, List[str] references)
Acquire the db and configure the interface with the compiled function.