Skip to content

Add Support for Selecting from a Table by Its Name #180

@v283

Description

@v283

Feature request : Add Overload to Select Table by Name

Is your feature request related to a problem? Please describe.

Currently, when working with the ProductModel class, the table name is specified using the [Table] attribute, e.g., [Table("coffeeteatable")]. This approach is static and requires the table name to be hardcoded in the attribute, making it less flexible for scenarios where the table name needs to be determined dynamically at runtime.
For instance, this method works as follows:
var products = await client.From<ProductModel>().Get();

But it does not allow specifying the table name dynamically, like this:

var products = await client.From<ProductModel>("my_table_name").Get();

Describe the solution you'd like

Introduce a new overload for the From method that accepts a table name as an argument. This would enable dynamically selecting the table at runtime without relying on the [Table] attribute.

For example:

var products = await client.From<ProductModel>("my_table_name").Get();
This approach would provide greater flexibility for developers working with multiple tables using the same model structure.

Describe alternatives you've considered

  1. Manually overriding the [Table] attribute: This is cumbersome and requires code changes every time the table name needs to be updated, defeating the purpose of runtime flexibility.

  2. Creating multiple models for each table: This leads to code duplication and maintenance issues, especially when the table structures are identical.

Additional context

Here is the current ProductModel class for reference:


[Table("coffeeteatable")]
public class ProductModel : BaseModel
{
    [PrimaryKey("id")]
    public int Id { get; set; }
    [Column("name")]
    public string Name { get; set; }
    [Column("image")]
    public string Image { get; set; }
    [Column("size")]
    public string Size { get; set; }
    [Column("categoty")]
    public string Categoty { get; set; }
    [Column("subcategory")]
    public string SubCategory { get; set; }
    [Column("subsubcategory")]
    public string SubSubCategory { get; set; }
    [Column("barcode")]
    public string Barcode { get; set; }
    [Column("about")]
    public string About { get; set; }
    [Column("shops")]
    public string Shops { get; set; }
    [Column("ratingtable")]
    public string RatingTable { get; set; }
    [Column("county")]
    public string Country { get; set; }
    [Column("trademark")]
    public string TradeMark { get; set; }
    [Column("price")]
    public string Price { get; set; }
}

The feature would simplify usage and improve developer experience, especially for scenarios where the table name varies dynamically.
Let me know if you’d like to add or modify anything!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions