@an5/adapters 0.2.6 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -2
- package/dist/an5Adapter.d.ts +57 -0
- package/dist/an5Adapter.js +263 -4
- package/dist/base/sql.js +16 -15
- package/dist/base/types.d.ts +6 -0
- package/dist/googlesheets/helpers.js +13 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -1
- package/dist/nbase/client.d.ts +92 -0
- package/dist/nbase/client.js +147 -0
- package/dist/nbase/index.d.ts +47 -0
- package/dist/nbase/index.js +80 -0
- package/dist/sqlite/engine.js +2 -1
- package/dotnet/An5Adapter.cs +41 -18
- package/dotnet/Base/Core.cs +56 -26
- package/dotnet/Postgres/PostgresEngine.cs +58 -30
- package/dotnet/Sqlite/SqliteEngine.cs +214 -0
- package/golang/base/where.go +32 -49
- package/golang/base/where_test.go +57 -0
- package/package.json +26 -11
- package/python/an5_adapter.py +74 -9
- package/python/base/__init__.py +1 -1
- package/python/base/metadata.py +25 -1
- package/python/base/sql.py +50 -21
- package/python/sqlite/__init__.py +3 -0
- package/python/sqlite/provider.py +83 -0
- package/python/table_client.py +53 -36
- package/rust/Cargo.toml +31 -0
- package/rust/README.md +71 -0
- package/rust/src/adapter.rs +1314 -0
- package/rust/src/base/dialect.rs +201 -0
- package/rust/src/base/metadata.rs +138 -0
- package/rust/src/base/mod.rs +17 -0
- package/rust/src/base/where_builder.rs +386 -0
- package/rust/src/lib.rs +75 -0
- package/typescript/src/an5Adapter.ts +300 -4
- package/typescript/src/base/sql.ts +15 -14
- package/typescript/src/base/types.ts +6 -0
- package/typescript/src/googlesheets/helpers.ts +11 -8
- package/typescript/src/index.ts +17 -0
- package/typescript/src/nbase/client.ts +214 -0
- package/typescript/src/nbase/index.ts +104 -0
- package/typescript/src/sqlite/engine.ts +2 -1
package/rust/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# an5-adapters
|
|
2
|
+
|
|
3
|
+
Database adapter runtime for [AN5 ORM](https://github.com/an5ORM/an5) in Rust.
|
|
4
|
+
|
|
5
|
+
`An5Adapter` owns the connection and the dialect; `TableClient` provides the ORM
|
|
6
|
+
CRUD surface on top of [`sqlx`](https://github.com/launchbadge/sqlx). Dialects are
|
|
7
|
+
detected from the connection string, so SQL Server, PostgreSQL and SQLite are
|
|
8
|
+
handled without configuration. This crate mirrors the TypeScript, Python, .NET
|
|
9
|
+
and Go adapter packages.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```toml
|
|
14
|
+
[dependencies]
|
|
15
|
+
an5-adapters = "0.1"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The crate is driver-agnostic: it depends on `sqlx` with `any`, so the application
|
|
19
|
+
picks the driver it needs and enables the matching `sqlx` feature.
|
|
20
|
+
|
|
21
|
+
```toml
|
|
22
|
+
[dependencies]
|
|
23
|
+
sqlx = { version = "0.8", default-features = false, features = ["any", "runtime-tokio", "postgres"] }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```rust
|
|
29
|
+
use an5_adapters::{An5Adapter, FindManyArgs};
|
|
30
|
+
use serde_json::json;
|
|
31
|
+
|
|
32
|
+
#[tokio::main]
|
|
33
|
+
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
34
|
+
// Register the drivers this binary needs, then hand the URL to the adapter.
|
|
35
|
+
sqlx::any::install_drivers(&[sqlx::postgres::any::DRIVER])?;
|
|
36
|
+
let db = An5Adapter::connect("postgres://localhost:5432/mydb").await?;
|
|
37
|
+
|
|
38
|
+
// Dynamic access, the Rust equivalent of `db.user` in TypeScript.
|
|
39
|
+
let users = db
|
|
40
|
+
.table("User")
|
|
41
|
+
.find_many(&FindManyArgs {
|
|
42
|
+
r#where: Some(json!({ "email": { "contains": "@example.com" } })),
|
|
43
|
+
take: 10,
|
|
44
|
+
..Default::default()
|
|
45
|
+
})
|
|
46
|
+
.await?;
|
|
47
|
+
|
|
48
|
+
println!("{} users", users.len());
|
|
49
|
+
Ok(())
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Generated Rust clients (`an5-client`) wrap this crate and expose one typed handle
|
|
54
|
+
per model — `db.user().find_many(&UserFindManyArgs { .. })` — instead of the
|
|
55
|
+
dynamic `db.table("User")` access shown above.
|
|
56
|
+
|
|
57
|
+
### Features
|
|
58
|
+
|
|
59
|
+
- `An5Adapter::connect` / `create_an5_adapter`, with the connection string read
|
|
60
|
+
from `DATABASE_URL` when omitted
|
|
61
|
+
- Dialect detection and identifier quoting for MSSQL, PostgreSQL and SQLite
|
|
62
|
+
- `TableClient`: `find_many`, `find_first`, `find_unique`, `count`, `create`,
|
|
63
|
+
`create_many`, `update`, `update_many`, `delete_many`, `upsert`, `aggregate`,
|
|
64
|
+
`group_by` and `vector_search`
|
|
65
|
+
- Transactions, raw SQL execution and view clients
|
|
66
|
+
- `base` module with the where/order-by builders, adapter metadata and vector
|
|
67
|
+
distance math
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|