@an5/orm 1.2.0 → 1.3.0

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.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/dist/generator/src/api.d.ts +3 -0
  3. package/dist/generator/src/api.js +7 -1
  4. package/dist/generator/src/code-generator.js +12 -1
  5. package/dist/generator/src/code-request.d.ts +2 -2
  6. package/dist/generator/src/code-request.js +24 -3
  7. package/dist/generator/src/config.d.ts +18 -0
  8. package/dist/generator/src/config.js +24 -0
  9. package/dist/generator/src/dialect.js +4 -2
  10. package/dist/generator/src/dotnet-generator.js +97 -1
  11. package/dist/generator/src/field-types.js +3 -0
  12. package/dist/generator/src/golang-generator.d.ts +8 -0
  13. package/dist/generator/src/golang-generator.js +183 -9
  14. package/dist/generator/src/index.js +18 -0
  15. package/dist/generator/src/java-generator.d.ts +56 -0
  16. package/dist/generator/src/java-generator.js +1406 -0
  17. package/dist/generator/src/kotlin-generator.d.ts +34 -0
  18. package/dist/generator/src/kotlin-generator.js +753 -0
  19. package/dist/generator/src/rust-generator.js +36 -1
  20. package/dist/generator/src/swift-generator.d.ts +42 -0
  21. package/dist/generator/src/swift-generator.js +768 -0
  22. package/generator/src/api.ts +3 -0
  23. package/generator/src/code-generator.ts +13 -1
  24. package/generator/src/code-request.ts +17 -3
  25. package/generator/src/config.ts +48 -0
  26. package/generator/src/dialect.ts +5 -3
  27. package/generator/src/dotnet-generator.ts +97 -1
  28. package/generator/src/field-types.ts +3 -0
  29. package/generator/src/golang-generator.ts +184 -9
  30. package/generator/src/index.ts +21 -0
  31. package/generator/src/java-generator.ts +1457 -0
  32. package/generator/src/kotlin-generator.ts +798 -0
  33. package/generator/src/rust-generator.ts +37 -1
  34. package/generator/src/swift-generator.ts +830 -0
  35. package/package.json +2 -2
@@ -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`);