Răsfoiți Sursa

refactor(orm): auto-set table name in register_with_schema

The table_name parameter passed to register_with_schema is now
automatically applied to the entity mapper builder, eliminating
the need for explicit b.table() calls within the build action.
clanker 1 lună în urmă
părinte
comite
a29d5534e3
2 a modificat fișierele cu 9 adăugiri și 12 ștergeri
  1. 1 0
      src/orm/type-registry.vala
  2. 8 12
      src/tests/orm-test.vala

+ 1 - 0
src/orm/type-registry.vala

@@ -60,6 +60,7 @@ namespace InvercargillSql.Orm {
             owned GLib.Func<EntityMapperBuilder<T>> build_action
         ) throws SqlError {
             var builder = new EntityMapperBuilder<T>();
+            builder.table(table_name);
             build_action(builder);
             
             // Introspect schema and apply to mapper

+ 8 - 12
src/tests/orm-test.vala

@@ -859,8 +859,7 @@ OrmSession setup_test_session() throws SqlError {
     """);
     
     // Register TestUser mapper with schema introspection on registry
-    registry.register_entity<TestUser>(EntityMapper.build_for<TestUser>(b => {
-        b.table("users");
+    registry.register_with_schema<TestUser>("users", conn, dialect, b => {
         b.column<int64?>("id", u => u.id, (u, v) => u.id = v);
         b.column<string>("name", u => u.name, (u, v) => u.name = v);
         b.column<string>("email", u => u.email, (u, v) => u.email = v);
@@ -868,7 +867,7 @@ OrmSession setup_test_session() throws SqlError {
         b.column<double?>("salary", u => u.salary, (u, v) => u.salary = v);
         b.column<bool?>("is_active", u => u.is_active, (u, v) => u.is_active = v);
         b.column<DateTime?>("created_at", u => u.created_at, (u, v) => u.created_at = v);
-    }));
+    });
     
     return new OrmSession(conn, registry, dialect);
 }
@@ -912,12 +911,11 @@ void test_orm_session_register_with_schema() throws Error {
     """);
     
     // Register with schema introspection on registry - PK and auto-increment discovered automatically
-    registry.register_entity<TestUser>(EntityMapper.build_for<TestUser>(b => {
-        b.table("users");
+    registry.register_with_schema<TestUser>("users", conn, dialect, b => {
         b.column<int64?>("id", u => u.id, (u, v) => u.id = v);
         b.column<string>("name", u => u.name, (u, v) => u.name = v);
         b.column<string>("email", u => u.email, (u, v) => u.email = v);
-    }));
+    });
     
     var session = new OrmSession(conn, registry, dialect);
     
@@ -1281,14 +1279,13 @@ OrmSession setup_product_session() throws SqlError {
         )
     """);
     
-    registry.register_entity<TestProduct>(EntityMapper.build_for<TestProduct>(b => {
-        b.table("products");
+    registry.register_with_schema<TestProduct>("products", conn, dialect, b => {
         b.column<int64?>("id", p => p.id, (p, v) => p.id = v);
         b.column<string>("name", p => p.name, (p, v) => p.name = v);
         b.column<string>("category", p => p.category, (p, v) => p.category = v);
         b.column<double?>("price", p => p.price, (p, v) => p.price = v);
         b.column<int64?>("stock", p => p.stock, (p, v) => p.stock = v);
-    }));
+    });
     
     return new OrmSession(conn, registry, dialect);
 }
@@ -1313,8 +1310,7 @@ OrmSession setup_order_session() throws SqlError {
         )
     """);
     
-    registry.register_entity<TestOrder>(EntityMapper.build_for<TestOrder>(b => {
-        b.table("orders");
+    registry.register_with_schema<TestOrder>("orders", conn, dialect, b => {
         b.column<int64?>("id", o => o.id, (o, v) => o.id = v);
         b.column<int64?>("user_id", o => o.user_id, (o, v) => o.user_id = v);
         b.column<int64?>("product_id", o => o.product_id, (o, v) => o.product_id = v);
@@ -1322,7 +1318,7 @@ OrmSession setup_order_session() throws SqlError {
         b.column<double?>("total", o => o.total, (o, v) => o.total = v);
         b.column<string>("status", o => o.status, (o, v) => o.status = v);
         b.column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
-    }));
+    });
     
     return new OrmSession(conn, registry, dialect);
 }