瀏覽代碼

refactor(orm): broaden exception types and remove deprecated query_projection

- Change exception declarations from specific types (SqlError, ProjectionError) to generic Error across ORM session and type provider interfaces
- Remove deprecated query_projection<TProjection>() method in favor of unified query<T>()
- Make build_with_schema() public in EntityMapperBuilder
- Add peek_table() method to expose table name for inspection
- Convert generic convenience methods in TypeProvider from abstract to virtual with default implementations

BREAKING CHANGE: Methods now throw Error instead of SqlError/ProjectionError. The query_projection<TProjection>() method has been removed; use query<T>() instead.
Billy Barrow 1 月之前
父節點
當前提交
3b8c7a5211

+ 5 - 1
src/orm/entity-mapper-builder.vala

@@ -109,11 +109,15 @@ namespace InvercargillSql.Orm {
          * @param schema The introspected table schema
          * @return A new EntityMapper instance with schema metadata applied
          */
-        internal EntityMapper<T> build_with_schema(TableSchema schema) {
+        public EntityMapper<T> build_with_schema(TableSchema schema) {
             var mapper = build();
             mapper.table_schema = schema;
             mapper.primary_key_column = schema.primary_key_column;
             return mapper;
         }
+
+        public string peek_table() {
+            return _table_name;
+        }
     }
 }

+ 9 - 33
src/orm/orm-session.vala

@@ -50,7 +50,7 @@ namespace InvercargillSql.Orm {
          * @return A new Query<T> instance appropriate for type T
          * @throws SqlError.GENERAL_ERROR if T is neither a registered entity nor projection
          */
-        public Query<T> query<T>() throws SqlError {
+        public Query<T> query<T>() throws Error {
             var type = typeof(T);
             
             // Check if it's a registered entity
@@ -77,7 +77,7 @@ namespace InvercargillSql.Orm {
          * @param entity The entity to insert
          * @throws SqlError if insertion fails
          */
-        public void insert<T>(T entity) throws SqlError {
+        public void insert<T>(T entity) throws Error {
             var mapper = get_mapper<T>();
             Invercargill.Properties properties;
             try {
@@ -130,7 +130,7 @@ namespace InvercargillSql.Orm {
          * @param entity The entity to update
          * @throws SqlError if update fails
          */
-        public void update<T>(T entity) throws SqlError {
+        public void update<T>(T entity) throws Error {
             var mapper = get_mapper<T>();
             Invercargill.Properties properties;
             try {
@@ -175,7 +175,7 @@ namespace InvercargillSql.Orm {
          * @param entity The entity to delete
          * @throws SqlError if deletion fails
          */
-        public void delete<T>(T entity) throws SqlError {
+        public void delete<T>(T entity) throws Error {
             var mapper = get_mapper<T>();
             Invercargill.Properties properties;
             try {
@@ -217,7 +217,7 @@ namespace InvercargillSql.Orm {
          * @return The EntityMapper<T> for type T
          * @throws SqlError if no mapper is registered for type T
          */
-        public EntityMapper<T> get_mapper<T>() throws SqlError {
+        public EntityMapper<T> get_mapper<T>() throws Error {
             return _type_provider.get_mapper<T>();
         }
         
@@ -227,41 +227,17 @@ namespace InvercargillSql.Orm {
          * @param type The entity type to look up
          * @return The EntityMapper for the type, or null if not registered
          */
-        public EntityMapper? get_mapper_for_type(Type type) {
+        public EntityMapper? get_mapper_for_type(Type type) throws Error {
             return _type_provider.get_mapper_for_type(type);
         }
-        
-        /**
-         * Creates a query for a projection type.
-         *
-         * @deprecated Use query<T>() instead, which automatically detects
-         *             whether T is an entity or projection type.
-         *
-         * For projections, returns ProjectionQuery<TProjection> for read-only queries.
-         *
-         * @return A new ProjectionQuery<TProjection> instance
-         * @throws ProjectionError.PROJECTION_NOT_REGISTERED if projection is not registered
-         */
-        [Deprecated (replacement = "query<T>()", since = "0.1")]
-        public ProjectionQuery<TProjection> query_projection<TProjection>()
-        {
-            var type = typeof(TProjection);
-            var definition = _type_provider.get_projection_for_type(type);
-            if (definition == null) {
-                throw new ProjectionError.PROJECTION_NOT_REGISTERED(
-                    @"Projection of type $(type.name()) is not registered"
-                );
-            }
-            var sql_builder = new ProjectionSqlBuilder(definition, _dialect);
-            return new ProjectionQuery<TProjection>(this, definition, sql_builder);
-        }
+    
         
         /**
          * Gets the projection definition for a type.
          * 
          * @return The ProjectionDefinition for the type, or null if not registered
          */
-        public ProjectionDefinition? get_projection_definition<TProjection>()
+        public ProjectionDefinition? get_projection_definition<TProjection>() throws Error
         {
             return _type_provider.get_projection<TProjection>();
         }
@@ -272,7 +248,7 @@ namespace InvercargillSql.Orm {
          * @param type The projection type to look up
          * @return The ProjectionDefinition for the type, or null if not registered
          */
-        public ProjectionDefinition? get_projection_definition_for_type(Type type) {
+        public ProjectionDefinition? get_projection_definition_for_type(Type type)  throws Error {
             return _type_provider.get_projection_for_type(type);
         }
         

+ 2 - 2
src/orm/projections/projection-builder.vala

@@ -52,7 +52,7 @@ namespace InvercargillSql.Orm.Projections {
          * @return This builder for method chaining
          * @throws ProjectionError.DUPLICATE_VARIABLE if source already defined or variable name already used
          */
-        public ProjectionBuilder<TProjection> source<TEntity>(string variable_name) throws ProjectionError {
+        public ProjectionBuilder<TProjection> source<TEntity>(string variable_name) throws Error {
             // Check if source is already defined
             if (_source_defined) {
                 throw new ProjectionError.DUPLICATE_VARIABLE(
@@ -97,7 +97,7 @@ namespace InvercargillSql.Orm.Projections {
          * @throws ProjectionError.DUPLICATE_VARIABLE if variable name already used
          * @throws ProjectionError if source has not been defined
          */
-        public ProjectionBuilder<TProjection> join<TEntity>(string variable_name, string join_condition) throws ProjectionError {
+        public ProjectionBuilder<TProjection> join<TEntity>(string variable_name, string join_condition) throws Error {
             // Ensure source is defined first
             if (!_source_defined) {
                 throw new ProjectionError.DUPLICATE_VARIABLE(

+ 6 - 6
src/orm/type-provider.vala

@@ -10,19 +10,19 @@ namespace InvercargillSql.Orm {
 public interface TypeProvider : Object {
     // Entity methods - non-generic versions taking Type parameter
     public abstract bool has_mapper_for_type(Type type);
-    public abstract EntityMapper? get_mapper_for_type(Type type);
+    public abstract EntityMapper? get_mapper_for_type(Type type) throws Error;
     
     // Entity methods - generic convenience versions
-    public abstract bool has_mapper<T>();
-    public abstract EntityMapper<T> get_mapper<T>() throws SqlError;
+    public virtual bool has_mapper<T>() { return has_mapper_for_type(typeof(T)); }
+    public virtual EntityMapper<T> get_mapper<T>() throws Error { return get_mapper_for_type(typeof(T)); }
     
     // Projection methods - non-generic versions taking Type parameter
     public abstract bool has_projection_for_type(Type type);
-    public abstract ProjectionDefinition? get_projection_for_type(Type type);
+    public abstract ProjectionDefinition? get_projection_for_type(Type type) throws Error;
     
     // Projection methods - generic convenience versions
-    public abstract bool has_projection<T>();
-    public abstract ProjectionDefinition? get_projection<T>();
+    public virtual bool has_projection<T>() { return has_projection_for_type(typeof(T)); }
+    public virtual ProjectionDefinition? get_projection<T>() throws Error { return get_projection_for_type(typeof(T)); }
 }
 
 }

+ 6 - 6
src/tests/projection-test.vala

@@ -1026,7 +1026,7 @@ void test_simple_projection_query() throws Error {
         .build()
     );
     
-    var query = ctx.session.query_projection<SimpleUserProjection>();
+    var query = ctx.session.query<SimpleUserProjection>();
     string sql = query.to_sql();
     print("\n  Generated SQL: %s\n", sql);
     
@@ -1061,7 +1061,7 @@ void test_projection_with_where() throws Error {
         .build()
     );
     
-    var query = ctx.session.query_projection<SimpleUserProjection>()
+    var query = ctx.session.query<SimpleUserProjection>()
         .where("u.age > 28");
     string sql = query.to_sql();
     print("\n  Generated SQL: %s\n", sql);
@@ -1085,7 +1085,7 @@ void test_projection_with_order_by() throws Error {
         .build()
     );
     
-    var results = ctx.session.query_projection<SimpleUserProjection>()
+    var results = ctx.session.query<SimpleUserProjection>()
         .order_by_desc("user_name")
         .materialise();
     
@@ -1111,7 +1111,7 @@ void test_projection_with_limit_offset() throws Error {
         .build()
     );
     
-    var results = ctx.session.query_projection<SimpleUserProjection>()
+    var results = ctx.session.query<SimpleUserProjection>()
         .order_by("user_id")
         .limit(2)
         .offset(1)
@@ -1142,7 +1142,7 @@ void test_projection_with_aggregates() throws Error {
         .build()
     );
     
-    var results = ctx.session.query_projection<UserOrderStats>()
+    var results = ctx.session.query<UserOrderStats>()
         .order_by("user_id")
         .materialise();
     
@@ -1182,7 +1182,7 @@ void test_projection_with_joins() throws Error {
         .build()
     );
     
-    var results = ctx.session.query_projection<UserOrderDetail>()
+    var results = ctx.session.query<UserOrderDetail>()
         .order_by("user_id")
         .materialise();