Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
v283 opened this issue Jan 9, 2025 · 0 comments
Open

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

v283 opened this issue Jan 9, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@v283
Copy link

v283 commented Jan 9, 2025

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!

@v283 v283 added the enhancement New feature or request label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant