Skip to content

Commit

Permalink
docs: moves embedded mode description to SpringQL-client-c
Browse files Browse the repository at this point in the history
  • Loading branch information
laysakura committed Nov 22, 2021
1 parent 92dffb7 commit 7a725e8
Showing 1 changed file with 2 additions and 100 deletions.
102 changes: 2 additions & 100 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,108 +138,10 @@ $ tail -f fst_trade_oracle.log

Client libraries for the following languages are currently available:

- [Rust](/SpringQL/SpringQL-client-rs)
- [C](/SpringQL/SpringQL-client-c)

This section describes how to use SpringQL in embedded mode from C.

#### Installation

**TODO** curl `libspringql.so` from GitHub releases in SpringQL-client-C repo?

#### Writing and building sample application

```c
// springql-embedded.c

#include <springql.h>
#include <assert.h>

void setup_pipeline(spring_pipeline *pipeline) {
spring_stmt *stmt = spring_prepare(
"CREATE STREAM \"st_trade_oracle\" ("
" \"timestamp\" TIMESTAMP NOT NULL ROWTIME,"
" \"ticker\" TEXT NOT NULL,"
" \"amount\" INTEGER NOT NULL"
");"
);
int r = spring_step(stmt);
assert(r, SPRING_OK);

spring_stmt *stmt = spring_prepare(
"CREATE PUMP \"pu_filter_oracle\" AS"
" INSERT INTO \"st_trade_oracle\" (\"timestamp\", \"ticker\", \"amount\")"
" SELECT STREAM \"timestamp\", \"ticker\", \"amount\" FROM \"fst_trade\" WHERE \"ticker\" = \"ORCL\";"
);
int r = spring_step(stmt);
assert(r, SPRING_OK);


spring_stmt *stmt = spring_prepare(
"CREATE FOREIGN STREAM \"fst_trade_oracle\" ("
" \"ts\" TIMESTAMP NOT NULL,"
" \"ticker\" TEXT NOT NULL,"
" \"amount\" INTEGER NOT NULL"
") SERVER IN_MEMORY_QUEUE;"
);
int r = spring_step(stmt);
assert(r, SPRING_OK);

spring_stmt *stmt = spring_prepare(
"CREATE PUMP \"pu_oracle_to_sink\" AS"
" INSERT INTO \"fst_trade_oracle\" (\"ts\", \"ticker\", \"amount\")"
" SELECT STREAM \"timestamp\", \"ticker\", \"amount\" FROM \"st_trade_oracle\";"
);
int r = spring_step(stmt);
assert(r, SPRING_OK);

spring_stmt *stmt = spring_prepare(
"ALTER PUMP \"pu_filter_oracle\", \"pu_oracle_to_sink\" START;"
);
int r = spring_step(stmt);
assert(r, SPRING_OK);
}

void query_pipeline(spring_pipeline *pipeline) {
spring_stmt *stmt = spring_prepare("SELECT \"ts\", \"ticker\", \"amount\" FROM \"fst_trade_oracle\";");

for (int i = 0; i < 5; ++i) {
int r = spring_step(stmt);
assert(r, SPRING_ROW);

const unsigned char *ts = spring_column_text(stmt, 0);
const unsigned char *ticker = spring_column_text(stmt, 1);
const int amount = spring_column_text(stmt, 2);

printf("[row#%d] ts=\"%s\" ticker=\"%s\" amount=%d\n", ts, ticker, amount);
}
}

int main() {
// Create a new pipeline
spring_pipeline *pipeline = spring_open();
assert(pipeline);

setup_pipeline(pipeline);

query_pipeline(pipeline);

// Close the pipeline
int r = spring_close(pipeline);
assert(r, SPRING_OK);

return 0;
}
```
```bash
$ gcc springql-embedded.c -lspringql
$ ./a.out
[row#0] ts="2021-10-28 13:23:34.826434031" ticker="ORCL" amount=100
...
[row#5] ts="2021-10-28 13:23:38.354213551" ticker="ORCL" amount=300
```
C client, for example, is composed of a header file and a dynamic library.
See [C client repository](/SpringQL/SpringQL-client-c) for more details on how to use SpringQL in embedded mode.

### IPC mode

Expand Down

0 comments on commit 7a725e8

Please sign in to comment.