Add Support for Selecting from a Table by Its Name

Open
#180 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
api, databases

Research direction

Start by locating the existing From() entry point in the C# client and trace how the model's Table attribute is resolved. Add the requested table-name overload so callers can select a table at runtime, then verify that Get() reads from the supplied table rather than the attribute-defined table.

Written by the indexing model from the issue text.

Description

feature

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!

Dominant language
C#
Stars
701
Forks
106
Avg merge
16h 35m
Merged PRs (30d)
45

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/supabase-csharp

All issues in supabase/supabase-csharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.