About the Persistence API
This API allows C/C++ Transformer modules to interface with the Caplin PersistenceService. This service allows Transformer to connect to either a local SQLite3 Database for development purposes or to any other database via a JDBC layer. Details about how to configure this module can be found on the Caplin website and the main Transformer SDK doc.
Notes:
- The default JDBC implementation uses ResultSetMetadata which is not implemented in all versions of the jdbc driver, please refer to the documentation of the driver of your choice for more details.
- If the default JDBC bridge does not satisfy all requirements then a custom implementation can be loaded into transformer by implementing the Persistor interface described in the online documentation Persistor.java
- Table and column names are not quoted and will hence be converted to whichever case the DBMS uses. The callbacks to get and query always get called with the column names converted to uppercase to help write DMBS independent code. Because of this behaviour it is recommended to use uppercase table and column names throughout the code
Example Snippets
The following section shows examples of how to retrieve and use the module from other C/C++ transformer modules. For information on how to use the module from LUA, JS or Java please refer to the Documentation of those modules.
Modules written in C or C++
- Retrieving the persistence interface
- This code snippet illustrates how to retrieve the persistence_interface from transformer which can then be used to call functions on
if ( ( get_persist =
tf_find_function(
"persistence_get_interface") ) != NULL ) {
persistence = get_persist();
}
- Upsert (update or insert) data in a table of your choice
- This snippet shows how to use persistence_interface::persist_upsert.
kv_pair keys_arr[] = { {
"ID",
"1" } };
{ "ID", "1"},
{ "NAME", "Adam"}
};
int ret = persistence->upsert("MY_TABLE", &keys, &data);
- Deletion of rows
- This snippet shows how to use persistence_interface::persist_remove.
kv_pair keys_arr[] = { {
"ID",
"1" } };
ret = persistence->remove("MY_TABLE", &selector);
- Retrieving data - Query
- This snippet shows how to use persistence_interface::persist_query.
}
{ "id", "5" },
{ "id", "10" }
};
ret = persistence->query("MY_TABLE", NULL, NULL, row_cb, NULL);
- Retrieving data - Get
- This snippet shows how to use persistence_interface::persist_get.
}
{ "FIRSTNAME", "Adam" },
{ "LASTNAME", "Bdam" }
};
ret = persistence->get("MY_TABLE", ¶ms, test_cb, &data);
FileDB library initialisation functionFunction to be added to FileDB stored procedure libraries to register stored procedures.
typedef int(* filedb_library_function) (void *ctx, const char *const *args, const size_t args_count, kv_pair_arr *output_params) |
FileDB library procedure functionFunction to be registered as a FileDB stored procedure.
typedef void(* persistence_query_cb) (void *context, const kv_pair_arr *row) |
Persistence query callback typeFor every entry returned by a persistence query a function of this type gets called to handle the received data.
Register FileDB stored procedure callbackCallback to register stored procedure functions for FileDB.