@an5/orm 1.2.0 → 1.3.1
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 +1 -1
- package/dist/generator/src/api.d.ts +3 -0
- package/dist/generator/src/api.js +7 -1
- package/dist/generator/src/code-generator.js +12 -1
- package/dist/generator/src/code-request.d.ts +2 -2
- package/dist/generator/src/code-request.js +24 -3
- package/dist/generator/src/config.d.ts +18 -0
- package/dist/generator/src/config.js +24 -0
- package/dist/generator/src/dialect.js +4 -2
- package/dist/generator/src/dotnet-generator.js +97 -1
- package/dist/generator/src/field-types.js +3 -0
- package/dist/generator/src/golang-generator.d.ts +8 -0
- package/dist/generator/src/golang-generator.js +183 -9
- package/dist/generator/src/index.js +18 -0
- package/dist/generator/src/java-generator.d.ts +56 -0
- package/dist/generator/src/java-generator.js +1408 -0
- package/dist/generator/src/kotlin-generator.d.ts +34 -0
- package/dist/generator/src/kotlin-generator.js +753 -0
- package/dist/generator/src/python-generator.js +4 -2
- package/dist/generator/src/rust-generator.js +36 -1
- package/dist/generator/src/swift-generator.d.ts +42 -0
- package/dist/generator/src/swift-generator.js +768 -0
- package/generator/src/api.ts +3 -0
- package/generator/src/code-generator.ts +13 -1
- package/generator/src/code-request.ts +17 -3
- package/generator/src/config.ts +48 -0
- package/generator/src/dialect.ts +5 -3
- package/generator/src/dotnet-generator.ts +97 -1
- package/generator/src/field-types.ts +3 -0
- package/generator/src/golang-generator.ts +184 -9
- package/generator/src/index.ts +21 -0
- package/generator/src/java-generator.ts +1459 -0
- package/generator/src/kotlin-generator.ts +798 -0
- package/generator/src/python-generator.ts +4 -2
- package/generator/src/rust-generator.ts +37 -1
- package/generator/src/swift-generator.ts +830 -0
- package/package.json +2 -2
|
@@ -64,7 +64,7 @@ export class PythonGenerator {
|
|
|
64
64
|
|
|
65
65
|
private generateOrmTypes(models: Model[], outputDir: string) {
|
|
66
66
|
let content = '# This file is auto-generated. Do not edit directly.\n';
|
|
67
|
-
content += '"""\nAN5 ORM typed filter/args dataclasses
|
|
67
|
+
content += '"""\nAN5 ORM typed filter/args dataclasses.\n\nThese describe the filter shapes the Python client accepts. The adapter reads plain\ndicts, not these dataclasses, and it quotes every key verbatim, so use the schema\nfield names (`createdAt`, not `created_at`):\n\n db.user.find_many(where={"name": {"contains": "John"}},\n order_by={"createdAt": "desc"},\n take=10)\n"""\n';
|
|
68
68
|
content += 'from __future__ import annotations\n';
|
|
69
69
|
content += 'from dataclasses import dataclass, field\n';
|
|
70
70
|
content += 'from typing import List, Optional, Any\n';
|
|
@@ -358,9 +358,11 @@ export class PythonGenerator {
|
|
|
358
358
|
|
|
359
359
|
content += 'class An5Client:\n';
|
|
360
360
|
content += ' """AN5 Python ORM Client - type-safe database access.\n\n';
|
|
361
|
+
content += ' Query keys are schema field names, used verbatim: the SQL builder quotes a key\n';
|
|
362
|
+
content += ' as-is, so `createdAt` reaches the database and `created_at` does not.\n\n';
|
|
361
363
|
content += ' Usage:\n';
|
|
362
364
|
content += ' db = An5Client()\n';
|
|
363
|
-
content += ' users = db.user.find_many(where={"name": {"contains": "John"}}, order_by={"
|
|
365
|
+
content += ' users = db.user.find_many(where={"name": {"contains": "John"}}, order_by={"createdAt": "asc"}, take=10)\n';
|
|
364
366
|
content += ' user = db.user.find_first(where={"id": "abc"})\n';
|
|
365
367
|
content += ' new = db.user.create(data={"name": "Alice", "email": "alice@example.com"})\n';
|
|
366
368
|
content += ' """\n';
|
|
@@ -502,6 +502,21 @@ pub struct DateTimeFilter {
|
|
|
502
502
|
s.push(` pub where_: Option<${name}WhereInput>,`);
|
|
503
503
|
s.push(`}\n`);
|
|
504
504
|
|
|
505
|
+
// VectorSearchArgs mirrors the runtime's, so a caller can narrow the search.
|
|
506
|
+
s.push(`/// ORM-style args for ${name}.vector_search().`);
|
|
507
|
+
s.push(`#[derive(Debug, Clone, Default, Serialize, Deserialize)]`);
|
|
508
|
+
s.push(`pub struct ${name}VectorSearchArgs {`);
|
|
509
|
+
s.push(` pub vector: Vec<f32>,`);
|
|
510
|
+
s.push(` #[serde(default, skip_serializing_if = "Option::is_none")]`);
|
|
511
|
+
s.push(` pub take: Option<i64>,`);
|
|
512
|
+
s.push(` #[serde(default, skip_serializing_if = "Option::is_none")]`);
|
|
513
|
+
s.push(` pub where_: Option<${name}WhereInput>,`);
|
|
514
|
+
s.push(` #[serde(default)]`);
|
|
515
|
+
s.push(` pub vector_field: String,`);
|
|
516
|
+
s.push(` #[serde(default)]`);
|
|
517
|
+
s.push(` pub distance_metric: String,`);
|
|
518
|
+
s.push(`}\n`);
|
|
519
|
+
|
|
505
520
|
// UpdateArgs carries the typed input alongside the where clause.
|
|
506
521
|
s.push(`/// ORM-style args for ${name}.update().`);
|
|
507
522
|
s.push(`#[derive(Debug, Clone, Default, Serialize, Deserialize)]`);
|
|
@@ -602,7 +617,7 @@ pub struct DateTimeFilter {
|
|
|
602
617
|
|
|
603
618
|
use an5_adapters::{
|
|
604
619
|
AdapterMetadata, An5Adapter, CountArgs, DeleteManyArgs, FindManyArgs, RowMap, TableClient,
|
|
605
|
-
UpdateArgs,
|
|
620
|
+
UpdateArgs, VectorSearchArgs,
|
|
606
621
|
};
|
|
607
622
|
use serde::de::DeserializeOwned;
|
|
608
623
|
|
|
@@ -825,6 +840,27 @@ impl SqlBuilder {
|
|
|
825
840
|
lines.push(` deserialize_rows(rows)`);
|
|
826
841
|
lines.push(` }`);
|
|
827
842
|
lines.push(``);
|
|
843
|
+
lines.push(` /// The rows nearest \`vector\`, each carrying a \`distance\`.`);
|
|
844
|
+
lines.push(` pub async fn vector_search(&self, args: &${name}VectorSearchArgs) -> Result<Vec<(${name}, f64)>> {`);
|
|
845
|
+
lines.push(` let rows = self`);
|
|
846
|
+
lines.push(` .db`);
|
|
847
|
+
lines.push(` .table("${model.name}")`);
|
|
848
|
+
lines.push(` .vector_search(&VectorSearchArgs {`);
|
|
849
|
+
lines.push(` vector: args.vector.iter().map(|v| *v as f64).collect(),`);
|
|
850
|
+
lines.push(` take: args.take.unwrap_or(0),`);
|
|
851
|
+
lines.push(` r#where: to_value(&args.where_)?,`);
|
|
852
|
+
lines.push(` vector_field: args.vector_field.clone(),`);
|
|
853
|
+
lines.push(` distance_metric: args.distance_metric.clone(),`);
|
|
854
|
+
lines.push(` ..Default::default()`);
|
|
855
|
+
lines.push(` })`);
|
|
856
|
+
lines.push(` .await?;`);
|
|
857
|
+
lines.push(` rows.into_iter().map(|row| {`);
|
|
858
|
+
lines.push(` let distance = row.get("distance").and_then(serde_json::Value::as_f64)`);
|
|
859
|
+
lines.push(` .ok_or("vector search returned no distance")?;`);
|
|
860
|
+
lines.push(` Ok((deserialize_row(row)?, distance))`);
|
|
861
|
+
lines.push(` }).collect()`);
|
|
862
|
+
lines.push(` }`);
|
|
863
|
+
lines.push(``);
|
|
828
864
|
lines.push(` pub async fn find_first(&self, args: &${name}FindFirstArgs) -> Result<Option<${name}>> {`);
|
|
829
865
|
lines.push(` let row = self`);
|
|
830
866
|
lines.push(` .db`);
|