Skip to content

Commit 44c4fb6

Browse files
committed
examples: update all
1 parent 41d5fd3 commit 44c4fb6

14 files changed

+146
-90
lines changed

Diff for: README.md

+9
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@
134134
./example
135135
```
136136
137+
## Examples
138+
139+
- [Local](/examples/local)
140+
- [Remote](/examples/remote)
141+
- [Sync](/examples/sync)
142+
- [Vector](/examples/vector)
143+
- [Transactions](/examples/transactions)
144+
- [Batch](/examples/batch)
145+
137146
## Documentation
138147
139148
Visit our [official documentation](https://docs.turso.tech/sdk/c).

Diff for: examples/Makefile.common

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CC = gcc
2+
LDFLAGS = -L../../target/release -Wl,-rpath,../../target/release
3+
LIBS = -llibsql
4+
5+
TARGET = example
6+
7+
all: $(TARGET)
8+
9+
../../target/release/liblibsql.so:
10+
@echo "Building libsql..."
11+
@cd ../.. && cargo build --release
12+
13+
$(TARGET): example.c ../../target/release/liblibsql.so
14+
$(CC) $(LDFLAGS) -o $@ $< $(LIBS)
15+
16+
clean:
17+
rm -f $(TARGET)
18+
19+
.PHONY: all clean

Diff for: examples/batch/Makefile

-15
This file was deleted.

Diff for: examples/batch/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Makefile.common

Diff for: examples/batch/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Batch
2+
3+
This example demonstrates how to use libsql to execute a batch of SQL statements.
4+
5+
## Building
6+
7+
```bash
8+
make
9+
```
10+
11+
## Running
12+
13+
Execute the example:
14+
15+
```bash
16+
./example
17+
```
18+
19+
This will create a local database, execute a batch of SQL statements (creating tables, inserting data, etc.), and then query the results.

Diff for: examples/local/Makefile

-15
This file was deleted.

Diff for: examples/local/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Makefile.common

Diff for: examples/local/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Local
2+
3+
This example demonstrates how to use libsql with a local SQLite file.
4+
5+
## Building
6+
7+
```bash
8+
make
9+
```
10+
11+
## Running
12+
13+
```bash
14+
./example
15+
```
16+
17+
This will connect to a local SQLite, insert some data, and query it.

Diff for: examples/remote/Makefile

-15
This file was deleted.

Diff for: examples/remote/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Makefile.common

Diff for: examples/remote/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Remote
2+
3+
This example demonstrates how to use libsql with a remote database.
4+
5+
## Building
6+
7+
```bash
8+
make
9+
```
10+
11+
## Running
12+
13+
```bash
14+
TURSO_DATABASE_URL="..." TURSO_AUTH_TOKEN="..." ./example
15+
```
16+
17+
This will connect to a remote database, insert some data, and query it.

Diff for: examples/sync/Makefile

-15
This file was deleted.

Diff for: examples/sync/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Makefile.common

Diff for: examples/sync/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Sync
2+
3+
This example demonstrates how to use libsql with a synced database (local file synced with a remote database).
4+
5+
## Building
6+
7+
```bash
8+
make
9+
```
10+
11+
## Running
12+
13+
```bash
14+
TURSO_DATABASE_URL="..." TURSO_AUTH_TOKEN="..." ./example
15+
```
16+
17+
This will create a local database file that syncs with a remote database, insert some data, and query it.

Diff for: examples/transactions/Makefile

-15
This file was deleted.

Diff for: examples/transactions/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Makefile.common

Diff for: examples/transactions/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Transactions
2+
3+
This example demonstrates how to use transactions with libsql. It shows how to start a transaction, perform multiple operations, and then commit or rollback the transaction.
4+
5+
## Building
6+
7+
```bash
8+
make
9+
```
10+
11+
## Running
12+
13+
```bash
14+
./example
15+
```
16+
17+
This example will:
18+
19+
1. Create a new table called `users`.
20+
2. Start a transaction.
21+
3. Insert multiple users within the transaction.
22+
4. Demonstrate how to rollback a transaction.
23+
5. Start another transaction.
24+
6. Insert more users and commit the transaction.
25+
7. Query and display the final state of the `users` table.

Diff for: examples/vector/Makefile

-15
This file was deleted.

Diff for: examples/vector/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Makefile.common

Diff for: examples/vector/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Vector
2+
3+
This example demonstrates how to use libsql vector search with a local database.
4+
5+
## Building
6+
7+
```bash
8+
make
9+
```
10+
11+
## Running
12+
13+
```bash
14+
./example
15+
```
16+
17+
This will create a local database file that with a table for embeddings, insert some data (including embeddings), and query using the vector similarity search function.

0 commit comments

Comments
 (0)