benxu.AppPlatform.Supabase.PostgreSQL 3.2.8

dotnet add package benxu.AppPlatform.Supabase.PostgreSQL --version 3.2.8
                    
NuGet\Install-Package benxu.AppPlatform.Supabase.PostgreSQL -Version 3.2.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="benxu.AppPlatform.Supabase.PostgreSQL" Version="3.2.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="benxu.AppPlatform.Supabase.PostgreSQL" Version="3.2.8" />
                    
Directory.Packages.props
<PackageReference Include="benxu.AppPlatform.Supabase.PostgreSQL" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add benxu.AppPlatform.Supabase.PostgreSQL --version 3.2.8
                    
#r "nuget: benxu.AppPlatform.Supabase.PostgreSQL, 3.2.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package benxu.AppPlatform.Supabase.PostgreSQL@3.2.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=benxu.AppPlatform.Supabase.PostgreSQL&version=3.2.8
                    
Install as a Cake Addin
#tool nuget:?package=benxu.AppPlatform.Supabase.PostgreSQL&version=3.2.8
                    
Install as a Cake Tool

benxu.AppPlatform.Supabase.PostgreSQL

Supabase PostgreSQL 實作套件,使用 Supabase.Postgrest 提供強型別的 CRUD、查詢與 RPC 呼叫能力,適合在 .NET MAUI App 中透過 Supabase 的 Data API 存取 PostgreSQL。

功能特色

  • 使用 Supabase.Postgrest 實作強型別資料模型查詢。
  • 提供 Insert / Upsert / Query / Update / Delete / RPC 服務介面。
  • 若系統中已有 IAuthService,可自動帶入使用者 JWT,配合 Supabase RLS。
  • 保持套件內聚,不把 Supabase.Postgrest 依賴擴散到既有平台 Core 抽象。

安裝

dotnet add package benxu.AppPlatform.Supabase.PostgreSQL

使用方式

1. 註冊服務

using benxu.AppPlatform.Supabase.PostgreSQL.Extensions;

builder.Services.AddSupabasePostgreSql(options =>
{
    options.ProjectUrl = "https://your-project.supabase.co";
    options.AnonKey = "YOUR_SUPABASE_ANON_KEY";
    options.Schema = "public";
    options.UseAuthTokenWhenAvailable = true;
});

2. 定義資料模型

using Supabase.Postgrest.Attributes;
using Supabase.Postgrest.Models;

[Table("profiles")]
public class ProfileModel : BaseModel
{
    [PrimaryKey("id", false)]
    public Guid Id { get; set; }

    [Column("display_name")]
    public string DisplayName { get; set; } = string.Empty;

    [Column("avatar_url")]
    public string? AvatarUrl { get; set; }
}

3. 查詢與寫入資料

using benxu.AppPlatform.Supabase.PostgreSQL.Abstractions;

public class ProfileRepository
{
    private readonly ISupabasePostgreSqlService _postgreSqlService;

    /// <summary>
    /// 建立 ProfileRepository
    /// </summary>
    /// <param name="postgreSqlService">Supabase PostgreSQL 服務</param>
    public ProfileRepository(ISupabasePostgreSqlService postgreSqlService)
    {
        _postgreSqlService = postgreSqlService;
    }

    /// <summary>
    /// 取得最近更新的使用者資料
    /// </summary>
    /// <returns>資料清單</returns>
    public async Task<IReadOnlyList<ProfileModel>> GetLatestProfilesAsync()
    {
        var result = await _postgreSqlService.QueryAsync<ProfileModel>(query =>
            query.OrderByDescending("updated_at")
                 .Limit(20));

        return result.IsSuccess ? result.Data : Array.Empty<ProfileModel>();
    }
}

注意事項

  • Model 必須繼承 BaseModel,並使用 [Table][PrimaryKey][Column] 屬性。
  • GetByIdAsync()DeleteByIdAsync() 目前僅支援單一主鍵欄位。
  • 若你的表格使用 RLS,建議同時註冊 benxu.AppPlatform.Supabase.Auth,讓本套件可自動帶入使用者 Access Token。

依賴項目

  • Supabase.Postgrest (4.1.0)
  • benxu.AppPlatform.Core
  • Microsoft.Maui.Controls

授權

MIT License

Product Compatible and additional computed target framework versions.
.NET net10.0-android36.0 is compatible.  net10.0-ios26.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on benxu.AppPlatform.Supabase.PostgreSQL:

Package Downloads
benxu.AppPlatform.MAUI.Bootstrap

Bootstrap package for benxu App Platform. Provides fluent API for one-line service registration and lifecycle management.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.8 81 7/7/2026