Skip to content

Commit

Permalink
examples: update all
Browse files Browse the repository at this point in the history
  • Loading branch information
notrab committed Oct 10, 2024
1 parent 41d5fd3 commit 44c4fb6
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 90 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@
./example
```
## Examples
- [Local](/examples/local)
- [Remote](/examples/remote)
- [Sync](/examples/sync)
- [Vector](/examples/vector)
- [Transactions](/examples/transactions)
- [Batch](/examples/batch)
## Documentation
Visit our [official documentation](https://docs.turso.tech/sdk/c).
Expand Down
19 changes: 19 additions & 0 deletions examples/Makefile.common
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CC = gcc
LDFLAGS = -L../../target/release -Wl,-rpath,../../target/release
LIBS = -llibsql

TARGET = example

all: $(TARGET)

../../target/release/liblibsql.so:
@echo "Building libsql..."
@cd ../.. && cargo build --release

$(TARGET): example.c ../../target/release/liblibsql.so
$(CC) $(LDFLAGS) -o $@ $< $(LIBS)

clean:
rm -f $(TARGET)

.PHONY: all clean
15 changes: 0 additions & 15 deletions examples/batch/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions examples/batch/Makefile
19 changes: 19 additions & 0 deletions examples/batch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Batch

This example demonstrates how to use libsql to execute a batch of SQL statements.

## Building

```bash
make
```

## Running

Execute the example:

```bash
./example
```

This will create a local database, execute a batch of SQL statements (creating tables, inserting data, etc.), and then query the results.
15 changes: 0 additions & 15 deletions examples/local/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions examples/local/Makefile
17 changes: 17 additions & 0 deletions examples/local/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Local

This example demonstrates how to use libsql with a local SQLite file.

## Building

```bash
make
```

## Running

```bash
./example
```

This will connect to a local SQLite, insert some data, and query it.
15 changes: 0 additions & 15 deletions examples/remote/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions examples/remote/Makefile
17 changes: 17 additions & 0 deletions examples/remote/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Remote

This example demonstrates how to use libsql with a remote database.

## Building

```bash
make
```

## Running

```bash
TURSO_DATABASE_URL="..." TURSO_AUTH_TOKEN="..." ./example
```

This will connect to a remote database, insert some data, and query it.
15 changes: 0 additions & 15 deletions examples/sync/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions examples/sync/Makefile
17 changes: 17 additions & 0 deletions examples/sync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Sync

This example demonstrates how to use libsql with a synced database (local file synced with a remote database).

## Building

```bash
make
```

## Running

```bash
TURSO_DATABASE_URL="..." TURSO_AUTH_TOKEN="..." ./example
```

This will create a local database file that syncs with a remote database, insert some data, and query it.
15 changes: 0 additions & 15 deletions examples/transactions/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions examples/transactions/Makefile
25 changes: 25 additions & 0 deletions examples/transactions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Transactions

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.

## Building

```bash
make
```

## Running

```bash
./example
```

This example will:

1. Create a new table called `users`.
2. Start a transaction.
3. Insert multiple users within the transaction.
4. Demonstrate how to rollback a transaction.
5. Start another transaction.
6. Insert more users and commit the transaction.
7. Query and display the final state of the `users` table.
15 changes: 0 additions & 15 deletions examples/vector/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions examples/vector/Makefile
17 changes: 17 additions & 0 deletions examples/vector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Vector

This example demonstrates how to use libsql vector search with a local database.

## Building

```bash
make
```

## Running

```bash
./example
```

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 comments on commit 44c4fb6

Please sign in to comment.