Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Simplify column names in generated structs for single-table queries #41

@tunamaguro

Description

@tunamaguro

Problem

Currently, generated row structs always include table prefixes in column names, even for single-table queries. This makes the generated code unnecessarily verbose.

Current behavior

For a simple query like:

SELECT id, name, bio FROM authors WHERE id = $1

The generated struct is:

pub struct GetAuthorRow {
    pub authors_id: i64,
    pub authors_name: String, 
    pub authors_bio: Option<String>,
}

Expected behavior

For single-table queries, column names should be simplified:

pub struct GetAuthorRow {
    pub id: i64,
    pub name: String,
    pub bio: Option<String>,
}

For multi-table queries (JOINs), table prefixes should be preserved to avoid naming conflicts.

Implementation plan

  1. Detect number of tables used in each query
  2. For single-table queries: remove table prefix from column names
  3. For multi-table queries: preserve current behavior with table prefixes
  4. Update column name generation logic in src/query.rs

Benefits

  • Cleaner, more readable generated code
  • Reduced verbosity for common single-table operations
  • Maintains compatibility for complex multi-table queries

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions