Skip to content

Commit 81b1c19

Browse files
authored
Merge pull request #37 from ocean/prepared-statement-updates
tests: Add more tests from the Ecto SQL adapter to strengthen our testing - SQL compatibility, streaming and transactions testing
2 parents d3abe21 + d997928 commit 81b1c19

15 files changed

Lines changed: 1582 additions & 1295 deletions

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,42 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
- **Statement Reset (`reset_stmt/2`)**
13+
- Explicitly reset prepared statements to initial state for efficient reuse
14+
- **Performance improvement**: 10-15x faster than re-preparing the same SQL string
15+
- Enables optimal statement reuse pattern: prepare once, execute many times with reset between executions
16+
- Rust NIF: `reset_statement()` in `src/statement.rs`
17+
- Elixir wrapper: `EctoLibSql.Native.reset_stmt/2`
18+
- Added 3 comprehensive tests covering explicit reset, multiple resets, and error handling
19+
- Usage: `EctoLibSql.Native.reset_stmt(state, stmt_id)` returns `:ok` or `{:error, reason}`
20+
21+
- **Statement Column Metadata (`get_stmt_columns/2`)**
22+
- Retrieve full column metadata from prepared statements
23+
- Returns column name, origin name, and declared type for all columns
24+
- **Use cases**: Type introspection for dynamic queries, schema discovery, better error messages, type casting hints
25+
- Rust NIF: `get_statement_columns()` in `src/statement.rs`
26+
- Elixir wrapper: `EctoLibSql.Native.get_stmt_columns/2`
27+
- Returns `{:ok, [{name, origin_name, decl_type}]}` tuples for each column
28+
- Added 4 comprehensive tests covering basic metadata, aliased columns, expressions, and error handling
29+
- Supports complex queries with aliases, joins, and aggregate functions
30+
31+
- **Remote Encryption Support for Turso Encrypted Databases**
32+
- Added support for Turso cloud encrypted databases via `remote_encryption_key` connection option
33+
- Complements existing local encryption (`encryption_key`) for at-rest database file encryption
34+
- **Encryption types**:
35+
- **Local encryption**: AES-256-CBC for local SQLite files (existing feature)
36+
- **Remote encryption**: Base64-encoded encryption key sent with each request to Turso (new feature)
37+
- **Connection modes supported**: Remote and Remote Replica
38+
- **Usage**: `remote_encryption_key: "base64-encoded-key"` in connection options
39+
- Remote replica mode can use both local and remote encryption simultaneously for end-to-end encryption
40+
- Updated Rust NIF: Enhanced `connect()` in `src/connection.rs` with `EncryptionContext` and `EncryptionKey::Base64Encoded`
41+
- Updated documentation in README.md with examples for all encryption scenarios
42+
- See [Turso Encryption Documentation](https://docs.turso.tech/cloud/encryption) for key generation and requirements
43+
844
## [0.8.1] - 2025-12-18
945

1046
### Fixed

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ For lower-level control, you can use the DBConnection interface directly:
9090

9191
**Advanced Features**
9292
- Vector similarity search
93-
- Database encryption (AES-256-CBC for local and embedded replica databases)
93+
- Database encryption (local AES-256-CBC and Turso remote encryption)
9494
- WebSocket and HTTP protocols
9595
- Cursor-based streaming for large result sets (via DBConnection interface)
9696
- Advanced replica synchronisation with frame tracking
@@ -303,23 +303,41 @@ distance_fn = EctoLibSql.Native.vector_distance_cos("embedding", query_vector)
303303

304304
### Database Encryption
305305

306+
EctoLibSql supports two types of encryption:
307+
- **Local encryption**: AES-256-CBC encryption for local database files (at-rest encryption)
308+
- **Remote encryption**: Turso encrypted databases (encryption key sent with each request)
309+
306310
```elixir
307-
# Encrypted local database
311+
# Encrypted local database (local file encryption)
308312
{:ok, conn} = DBConnection.start_link(EctoLibSql,
309313
database: "encrypted.db",
310314
encryption_key: "your-secret-key-must-be-at-least-32-characters"
311315
)
312316

313-
# Encrypted embedded replica
317+
# Encrypted remote database (Turso cloud encryption)
318+
{:ok, conn} = DBConnection.start_link(EctoLibSql,
319+
uri: "libsql://your-encrypted-db.turso.io",
320+
auth_token: "your-token",
321+
remote_encryption_key: "base64-encoded-encryption-key"
322+
)
323+
324+
# Encrypted embedded replica (both local and remote encryption)
314325
{:ok, conn} = DBConnection.start_link(EctoLibSql,
315326
database: "encrypted.db",
316-
uri: "libsql://your-db.turso.io",
327+
uri: "libsql://your-encrypted-db.turso.io",
317328
auth_token: "your-token",
318-
encryption_key: "your-secret-key-must-be-at-least-32-characters",
329+
encryption_key: "your-local-encryption-key-32-chars-min",
330+
remote_encryption_key: "base64-encoded-remote-encryption-key",
319331
sync: true
320332
)
321333
```
322334

335+
**Notes**:
336+
- `encryption_key`: Used for local file encryption (local and embedded replica modes)
337+
- `remote_encryption_key`: Used for Turso encrypted databases (remote and embedded replica modes)
338+
- Remote encryption keys should be base64-encoded as per Turso's encryption requirements
339+
- See [Turso Encryption Documentation](https://docs.turso.tech/cloud/encryption) for more details
340+
323341
### Embedded Replica Synchronisation
324342

325343
When using embedded replica mode (`sync: true`), the library automatically handles synchronisation between your local database and Turso cloud. However, you can also trigger manual sync when needed.
@@ -404,7 +422,8 @@ This is useful for offline-first applications or when you want explicit control
404422
| `uri` | string | Remote LibSQL server URI (e.g., `libsql://...` or `wss://...`) |
405423
| `auth_token` | string | Authentication token for remote connections |
406424
| `sync` | boolean | Enable automatic synchronisation for embedded replicas |
407-
| `encryption_key` | string | Encryption key (32+ characters) for local database |
425+
| `encryption_key` | string | Encryption key (32+ characters) for local database file encryption (AES-256-CBC) |
426+
| `remote_encryption_key` | string | Base64-encoded encryption key for Turso encrypted databases |
408427

409428
## Connection Modes
410429

RESILIENCE_IMPROVEMENTS.md

Lines changed: 0 additions & 242 deletions
This file was deleted.

0 commit comments

Comments
 (0)