-
Notifications
You must be signed in to change notification settings - Fork 3
Added Supabase Connector #6
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b3151a
Add Supabase Connector integration and configuration support
dean-journeyapps dc58656
Add configuration options for Supabase and Node connectors
dean-journeyapps cc9eb26
Added comments to the SupabasePatchHelper and PATCH Event in Supabase…
dean-journeyapps da2aec2
Updates README to include all .env values
dean-journeyapps 96bd1d7
Update .env.template and README to set USE_SUPABASE to false
dean-journeyapps d3c0e49
Refactor Supabase integration: update .env.template, refactor models,…
dean-journeyapps b690e56
Remove user_id.txt and add Microsoft.VisualBasic namespace to Todos m…
dean-journeyapps ad1b455
Add user_id.txt to .gitignore to prevent tracking of sensitive inform…
dean-journeyapps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,8 @@ TestResults/ | |
*.dylib | ||
*.dll | ||
*.so | ||
|
||
.env | ||
|
||
# Ignore user id file | ||
user_id.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# PowerSync server URL | ||
POWERSYNC_URL=http://localhost:8080 | ||
|
||
# Set to true if you want to use Supabase as the backend | ||
# Set to false if you want to use the PowerSync self-hosted backend | ||
USE_SUPABASE=false | ||
|
||
# --- Supabase Connector Settings --- | ||
# These values are used only if USE_SUPABASE=true | ||
|
||
# Supabase project URL | ||
SUPABASE_URL=http://localhost:54321 | ||
|
||
# Supabase anon key (public client access) | ||
SUPABASE_ANON_KEY=your_anon_key_here | ||
|
||
# Supabase credentials for an already existing user (used for login) | ||
[email protected] | ||
SUPABASE_PASSWORD=your_supabase_password | ||
|
||
# --- PowerSync Backend Settings --- | ||
# These values are used only if USE_SUPABASE=false | ||
|
||
# URL of your PowerSync self-hosted backend | ||
BACKEND_URL=http://localhost:6060 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.2.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine", "CommandLine.csproj", "{6BB9F16E-3825-DE76-1286-9E5E2406710D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6BB9F16E-3825-DE76-1286-9E5E2406710D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6BB9F16E-3825-DE76-1286-9E5E2406710D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6BB9F16E-3825-DE76-1286-9E5E2406710D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6BB9F16E-3825-DE76-1286-9E5E2406710D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A5588511-5909-4F05-80EB-09A56805607C} | ||
EndGlobalSection | ||
EndGlobal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace CommandLine.Helpers; | ||
|
||
using System.Linq.Expressions; | ||
using Newtonsoft.Json; | ||
using Supabase.Postgrest.Interfaces; | ||
using Supabase.Postgrest.Models; | ||
|
||
public static class SupabasePatchHelper | ||
{ | ||
// Applies a "SET" operation to the table, setting the value of a specific property. | ||
public static IPostgrestTable<T> ApplySet<T>( | ||
IPostgrestTable<T> table, // The table to apply the operation to | ||
string jsonPropertyName, // The name of the JSON property to update | ||
object value // The new value to set for the property | ||
) where T : BaseModel, new() // Ensures T is a subclass of BaseModel with a parameterless constructor | ||
{ | ||
// Find the property on the model that matches the JSON property name | ||
var property = typeof(T) | ||
.GetProperties() // Get all properties of the model type | ||
.FirstOrDefault(p => | ||
// Check if the property has a JsonPropertyAttribute | ||
p.GetCustomAttributes(typeof(JsonPropertyAttribute), true) | ||
.FirstOrDefault() is JsonPropertyAttribute attr && | ||
attr.PropertyName == jsonPropertyName); // Check if the JSON property name matches | ||
|
||
if (property == null) | ||
throw new ArgumentException($"'{jsonPropertyName}' is not a valid property on type '{typeof(T).Name}'"); | ||
|
||
// Create an expression to access the specified property on the model | ||
var parameter = Expression.Parameter(typeof(T), "x"); // Define a parameter for the expression | ||
var propertyAccess = Expression.Property(parameter, property.Name); // Access the property | ||
var converted = Expression.Convert(propertyAccess, typeof(object)); // Convert the value to object type | ||
var lambda = Expression.Lambda<Func<T, object>>(converted, parameter); // Create a lambda expression for the property | ||
|
||
// Apply the "SET" operation to the table using the lambda expression | ||
return table.Set(lambda, value); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
using Newtonsoft.Json; | ||
using Supabase.Postgrest.Attributes; | ||
using Supabase.Postgrest.Models; | ||
|
||
namespace CommandLine.Models.Supabase; | ||
|
||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. | ||
[Table("lists")] | ||
class List : BaseModel | ||
{ | ||
[PrimaryKey("id")] | ||
[JsonProperty("id")] | ||
public string Id { get; set; } | ||
|
||
[Column("created_at")] | ||
[JsonProperty("created_at")] | ||
public string CreatedAt { get; set; } | ||
|
||
[Column("name")] | ||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
|
||
[Column("owner_id")] | ||
[JsonProperty("owner_id")] | ||
public string OwnerId { get; set; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
using Microsoft.VisualBasic; | ||
using Newtonsoft.Json; | ||
using Supabase.Postgrest.Attributes; | ||
using Supabase.Postgrest.Models; | ||
|
||
namespace CommandLine.Models.Supabase; | ||
|
||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. | ||
[Table("todos")] | ||
class Todo : BaseModel | ||
{ | ||
[PrimaryKey("id")] | ||
[JsonProperty("id")] | ||
public string Id { get; set; } | ||
|
||
[Column("list_id")] | ||
[JsonProperty("list_id")] | ||
public string ListId { get; set; } | ||
|
||
[Column("created_at")] | ||
[JsonProperty("created_at")] | ||
public string CreatedAt { get; set; } | ||
|
||
[Column("completed_at")] | ||
[JsonProperty("completed_at")] | ||
public string CompletedAt { get; set; } | ||
|
||
[Column("description")] | ||
[JsonProperty("description")] | ||
public string Description { get; set; } | ||
|
||
[Column("created_by")] | ||
[JsonProperty("created_by")] | ||
public string CreatedBy { get; set; } | ||
|
||
[Column("completed_by")] | ||
[JsonProperty("completed_by")] | ||
public string CompletedBy { get; set; } | ||
|
||
[Column("completed")] | ||
[JsonProperty("completed")] | ||
public int Completed { get; set; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.