Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- **Statement Reset (`reset_stmt/2`)**
- Explicitly reset prepared statements to initial state for efficient reuse
- **Performance improvement**: 10-15x faster than re-preparing the same SQL string
- Enables optimal statement reuse pattern: prepare once, execute many times with reset between executions
- Rust NIF: `reset_statement()` in `src/statement.rs`
- Elixir wrapper: `EctoLibSql.Native.reset_stmt/2`
- Added 3 comprehensive tests covering explicit reset, multiple resets, and error handling
- Usage: `EctoLibSql.Native.reset_stmt(state, stmt_id)` returns `:ok` or `{:error, reason}`

- **Statement Column Metadata (`get_stmt_columns/2`)**
- Retrieve full column metadata from prepared statements
- Returns column name, origin name, and declared type for all columns
- **Use cases**: Type introspection for dynamic queries, schema discovery, better error messages, type casting hints
- Rust NIF: `get_statement_columns()` in `src/statement.rs`
- Elixir wrapper: `EctoLibSql.Native.get_stmt_columns/2`
- Returns `{:ok, [{name, origin_name, decl_type}]}` tuples for each column
- Added 4 comprehensive tests covering basic metadata, aliased columns, expressions, and error handling
- Supports complex queries with aliases, joins, and aggregate functions

- **Remote Encryption Support for Turso Encrypted Databases**
- Added support for Turso cloud encrypted databases via `remote_encryption_key` connection option
- Complements existing local encryption (`encryption_key`) for at-rest database file encryption
- **Encryption types**:
- **Local encryption**: AES-256-CBC for local SQLite files (existing feature)
- **Remote encryption**: Base64-encoded encryption key sent with each request to Turso (new feature)
- **Connection modes supported**: Remote and Remote Replica
- **Usage**: `remote_encryption_key: "base64-encoded-key"` in connection options
- Remote replica mode can use both local and remote encryption simultaneously for end-to-end encryption
- Updated Rust NIF: Enhanced `connect()` in `src/connection.rs` with `EncryptionContext` and `EncryptionKey::Base64Encoded`
- Updated documentation in README.md with examples for all encryption scenarios
- See [Turso Encryption Documentation](https://docs.turso.tech/cloud/encryption) for key generation and requirements

## [0.8.1] - 2025-12-18

### Fixed
Expand Down
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ For lower-level control, you can use the DBConnection interface directly:

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

### Database Encryption

EctoLibSql supports two types of encryption:
- **Local encryption**: AES-256-CBC encryption for local database files (at-rest encryption)
- **Remote encryption**: Turso encrypted databases (encryption key sent with each request)

```elixir
# Encrypted local database
# Encrypted local database (local file encryption)
{:ok, conn} = DBConnection.start_link(EctoLibSql,
database: "encrypted.db",
encryption_key: "your-secret-key-must-be-at-least-32-characters"
)

# Encrypted embedded replica
# Encrypted remote database (Turso cloud encryption)
{:ok, conn} = DBConnection.start_link(EctoLibSql,
uri: "libsql://your-encrypted-db.turso.io",
auth_token: "your-token",
remote_encryption_key: "base64-encoded-encryption-key"
)

# Encrypted embedded replica (both local and remote encryption)
{:ok, conn} = DBConnection.start_link(EctoLibSql,
database: "encrypted.db",
uri: "libsql://your-db.turso.io",
uri: "libsql://your-encrypted-db.turso.io",
auth_token: "your-token",
encryption_key: "your-secret-key-must-be-at-least-32-characters",
encryption_key: "your-local-encryption-key-32-chars-min",
remote_encryption_key: "base64-encoded-remote-encryption-key",
sync: true
)
```

**Notes**:
- `encryption_key`: Used for local file encryption (local and embedded replica modes)
- `remote_encryption_key`: Used for Turso encrypted databases (remote and embedded replica modes)
- Remote encryption keys should be base64-encoded as per Turso's encryption requirements
- See [Turso Encryption Documentation](https://docs.turso.tech/cloud/encryption) for more details

### Embedded Replica Synchronisation

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.
Expand Down Expand Up @@ -404,7 +422,8 @@ This is useful for offline-first applications or when you want explicit control
| `uri` | string | Remote LibSQL server URI (e.g., `libsql://...` or `wss://...`) |
| `auth_token` | string | Authentication token for remote connections |
| `sync` | boolean | Enable automatic synchronisation for embedded replicas |
| `encryption_key` | string | Encryption key (32+ characters) for local database |
| `encryption_key` | string | Encryption key (32+ characters) for local database file encryption (AES-256-CBC) |
| `remote_encryption_key` | string | Base64-encoded encryption key for Turso encrypted databases |

## Connection Modes

Expand Down
242 changes: 0 additions & 242 deletions RESILIENCE_IMPROVEMENTS.md

This file was deleted.

Loading