@an5/orm 1.1.1 → 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.
- package/README.md +5 -1
- package/dist/generator/src/api.d.ts +5 -0
- package/dist/generator/src/api.js +11 -1
- package/dist/generator/src/code-generator.js +12 -1
- package/dist/generator/src/code-request.d.ts +26 -0
- package/dist/generator/src/code-request.js +122 -0
- 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 +1406 -0
- package/dist/generator/src/kotlin-generator.d.ts +34 -0
- package/dist/generator/src/kotlin-generator.js +753 -0
- package/dist/generator/src/metadata-generator.js +3 -1
- 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/dist/migration-core.d.ts +1 -1
- package/dist/migration-core.js +6 -4
- package/generator/src/api.ts +5 -0
- package/generator/src/code-generator.ts +13 -1
- package/generator/src/code-request.ts +95 -0
- 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 +1457 -0
- package/generator/src/kotlin-generator.ts +798 -0
- package/generator/src/metadata-generator.ts +2 -1
- package/generator/src/rust-generator.ts +37 -1
- package/generator/src/swift-generator.ts +830 -0
- package/package.json +2 -2
|
@@ -31,7 +31,7 @@ export class MetadataGenerator {
|
|
|
31
31
|
}
|
|
32
32
|
metaContent += '};\n\n';
|
|
33
33
|
|
|
34
|
-
metaContent += 'export const modelFields: Record<string, Record<string, { ts: string; sql: string; description?: string }>> = {\n';
|
|
34
|
+
metaContent += 'export const modelFields: Record<string, Record<string, { ts: string; sql: string; isId?: boolean; description?: string }>> = {\n';
|
|
35
35
|
for (const model of models) {
|
|
36
36
|
const props = this.getAllPropertyVariations(model.name);
|
|
37
37
|
const fieldsStr = `{ ${model.fields.map(f => `${f.name}: ${this.formatFieldMetadata(f)}`).join(', ')} }`;
|
|
@@ -103,6 +103,7 @@ export class MetadataGenerator {
|
|
|
103
103
|
`ts: ${JSON.stringify(`${field.type}${field.isOptional ? '?' : ''}`)}`,
|
|
104
104
|
`sql: ${JSON.stringify(field.sqlType)}`,
|
|
105
105
|
];
|
|
106
|
+
if (field.isId) entries.push('isId: true');
|
|
106
107
|
if (field.description) {
|
|
107
108
|
entries.push(`description: ${JSON.stringify(field.description)}`);
|
|
108
109
|
}
|
|
@@ -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`);
|