Closed kurikin closed 3 months ago
Hi thanks for opening an issue and for pointing it out, will work on it asap!
@kurikin CLI and Web app now supports enums (I believe so, as I've written some tests for them). Please update your CLI and generate new types.
Make sure to also read this new part of docs for enums crud https://github.com/mmvergara/supadart?tab=readme-ov-file#enums-crud
We'll keep this issue open for now, Looking forward to your feedback.
@mmvergara Thank you for your incredibly quick response and implementation!
I've updated the CLI and tested the new version. The new enum support is working well overall, but I've discovered a minor issue that occurs in specific cases:
When the enum name contains uppercase letters (e.g., Mood
or MoodType
), the generated Dart file wraps the enum name in double quotes.
Here's an example:
For a Mood
enum used in a Person
table, the generated code looks like this:
enum "MOOD" { happy, sad, excited, calm }
class Person implements SupadartClass<Person> {
// [supadart:has_enums]
final int id;
final String? name;
final "MOOD"? current_mood;
const Person({
required this.id,
this.name,
this.current_mood,
});
}
As you can see, "MOOD"
is wrapped in double quotes, which isn't valid Dart syntax.
Could you please update the code generation to remove these quotes for enum names? Thank you again for your fantastic work on this library!
@kurikin I see, that's really weird cause i tried it in the same scenario and the way it is coded.
Could you possibly provide the configs printed out by the cli along with the Person Table schema?
@mmvergara Thank you for looking into this. I'm sharing the project URL and anon key. There's no sensitive data in this project, so it's safe to share:
Project URL: https://qglwwwspmytyeqeqxtbz.supabase.co
Anon key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InFnbHd3d3NwbXl0eWVxZXF4dGJ6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjMyODMyMTYsImV4cCI6MjAzODg1OTIxNn0.vR1lhJBFDqLg1H1_9X2I0Lu1Zu3hl2xm907M-YuyW08
> dart cli/bin/supadart.dart
π Supadart v1.5.0
==============================
URL: https://qglwwwspmytyeqeqxtbz.supabase.co
ANON KEY: eyJhbGciOiJIUzI1NiIsInR5c...
Output: lib/models/
Separated: true
Dart: false
Mappings: null
==============================
Generating...
π― Generated: lib/models/generated_enums.dart
π― Generated: lib/models/models.dart
π― Generated: lib/models/client_extension.dart
π― Generated: lib/models/supadart_abstract_class.dart
π― Generated: lib/models/person.dart
π Done!
@kurikin Thanks for your patience. It should be fix now, try updating the cli
@mmvergara Thank you for the quick fix. I've tested the latest version, and I can confirm that the issue with enum handling has been resolved. I appreciate your prompt attention to this matter and the rapid improvement.
@kurikin Aightt, thank you again for opening this issue, try to reset your anon key if you can, even though its safe.. just in case.
Hi @mmvergara First, I'd like to express my gratitude for creating supadart. It's an excellent library that significantly enhances the Dart development experience with Supabase. I have a suggestion regarding model generation, specifically concerning the handling of Enum types.
Current Behavior
When using Enum types in the database schema, as described in the Supabase documentation (https://supabase.com/docs/guides/database/postgres/enums), the current version of supadart is unable to generate the corresponding Dart models correctly.
For example, given the following schema:
Attempting to generate a model for this schema results in an error message:
Feature Request
I propose adding support for Enum types in the model generation process. This would allow developers to seamlessly work with Enum fields in their Supabase schemas and corresponding Dart models.
BR