Skip to content

Commit

Permalink
declare init api
Browse files Browse the repository at this point in the history
  • Loading branch information
levkk committed Jan 6, 2025
1 parent 052d702 commit cc341cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/routing-plugin-c/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ void pgdog_init() {

Route pgdog_route_query(Query query) {
Route route;
route.shard = ANY; /* No sharding */

char *lowercase = strdup(query.query);

for (int i = 0; i < strlen(lowercase); i++) {
Expand Down
20 changes: 20 additions & 0 deletions pgdog-plugin/include/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,29 @@
* implements it, the query router will use its decision
* to route the query.
*
* ## Thread safety
*
* This function is not synchronized and can be called
* for multiple queries at a time. If accessing global state,
* make sure to protect access with a mutex.
*
* ## Performance
*
* This function is called for every transaction. It's a hot path,
* so make sure to optimize for performance in the implementation.
*
*/
Route pgdog_route_query(Query query);

/*
* Perform initialization at plugin loading time.
*
* Executed only once and execution is synchronized,
* so it's safe to initialize sychroniziation primitives
* like mutexes in this method.
*/
void pgdog_init();

/* Create new row.
*
* Implemented by pgdog_plugin library.
Expand Down

0 comments on commit cc341cd

Please sign in to comment.