-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce8bdb4
commit 6846d6a
Showing
9 changed files
with
301 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: test-lib | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "prql-lib/**" | ||
- ".github/workflows/test-lib.yaml" | ||
workflow_call: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 📂 Checkout code | ||
uses: actions/checkout@v3 | ||
- name: 💰 Cache | ||
uses: Swatinem/rust-cache@v2 | ||
with: | ||
key: ${{ inputs.target_option }} | ||
save-if: ${{ github.ref == 'refs/heads/main' }} | ||
- name: Build | ||
uses: richb-hanover/cargo@v1.1.0 | ||
with: | ||
command: build | ||
args: --release -p prql-lib | ||
- name: Run basic C example | ||
working-directory: prql-lib/examples/minimal-c | ||
run: make run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
PRQL_PROJECT=../../.. | ||
|
||
build-prql: | ||
cargo build -p prql-lib --release | ||
|
||
build: main.c build-prql | ||
gcc main.c -o main.out \ | ||
-I${PRQL_PROJECT}/prql-lib \ | ||
-L${PRQL_PROJECT}/target/release \ | ||
-l:libprql_lib.a \ | ||
-pthread -ldl -lm | ||
|
||
run: build | ||
./main.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Basic C example | ||
|
||
A minimal example for using prql-lib with `gcc` and `make`. | ||
|
||
## How to run | ||
|
||
make run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <stdio.h> | ||
|
||
#include <libprql_lib.h> | ||
|
||
int main() { | ||
char *prql_query; | ||
prql_query = "from albums | select [album_id, title] | take 3"; | ||
|
||
int res; | ||
char res_buffer[256]; | ||
|
||
// default compile option | ||
res = compile(prql_query, NULL, res_buffer); | ||
printf("%s\n\n", res_buffer); | ||
|
||
// custom compile options | ||
Options opts; | ||
opts.format = false; | ||
opts.signature_comment = false; | ||
opts.target = "sql.mssql"; | ||
res = compile(prql_query, &opts, res_buffer); | ||
printf("%s\n\n", res_buffer); | ||
|
||
// error handling | ||
res = compile("from album | select [album_id] | select [title]", NULL, res_buffer); | ||
if (res == 0) { | ||
printf("success\n\n"); | ||
} | ||
if (res < 0) { | ||
printf("error with code %d!\n%s\n\n", res, res_buffer); | ||
} | ||
|
||
// intermediate results | ||
char* pl_buffer = (char*) malloc(sizeof(char) * 512); | ||
char* rq_buffer = (char*) malloc(sizeof(char) * 512); | ||
|
||
res = prql_to_pl(prql_query, pl_buffer); | ||
printf("PL JSON: %s\n\n", pl_buffer); | ||
|
||
res = pl_to_rq(pl_buffer, rq_buffer); | ||
printf("RQ JSON: %s\n\n", rq_buffer); | ||
|
||
free(pl_buffer); | ||
free(rq_buffer); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.