Skip to content

Commit

Permalink
Merge pull request #116 from mmvergara/fix-enum-case-sensitive
Browse files Browse the repository at this point in the history
Fix enum case sensitive
  • Loading branch information
mmvergara authored Dec 20, 2024
2 parents 8f80f83 + 77aaec5 commit e27c0fd
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,12 @@ await supabase.books.delete().eq(Books.c_id, 1);

- You need to specify your enums on supadart.yaml config file
- Enum `names` are converted to `UPPERCASE` to follow dart enum naming conventions
- Enum `values` are converted to `LOWERCASE` to follow dart enum naming conventions
- Optional: We recommend defining the enum values as lowercase to follow dart enum naming conventions

Assuming the following schema

```sql
-- We recommend defining the enum values as lowercase to follow dart enum naming conventions
CREATE TYPE mood AS ENUM ('happy', 'sad', 'neutral', 'excited', 'angry');
CREATE TABLE enum_types (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
Expand Down
4 changes: 4 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.7.0

- Revert changes on upperCasing generated enum values (postgres enums are case-sensitive)

## 1.6.9

- Enum `names` are converted to `UPPERCASE` to follow dart enum naming conventions
Expand Down
2 changes: 1 addition & 1 deletion cli/bin/supadart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:supadart/generators/storage/fetch_storage.dart';
import 'package:supadart/generators/utils/fetch_swagger.dart';
import 'package:yaml/yaml.dart';

const String version = 'v1.6.9';
const String version = 'v1.7.0';
const String red = '\x1B[31m';
const String green = '\x1B[32m';
const String blue = '\x1B[34m';
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/generators/standalone/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ String generateEnums(Map<String, List<String>> mapOfEnums) {
final code = StringBuffer();
mapOfEnums.forEach((enumName, enumValues) {
code.write(
"enum ${enumName.split(".").last.toUpperCase().replaceAll('"', "")} { ${enumValues.map((e) => e.toLowerCase()).join(", ")} }\n");
"enum ${enumName.split(".").last.toUpperCase().replaceAll('"', "")} { ${enumValues.join(", ")} }\n");
});
return code.toString();
}
4 changes: 2 additions & 2 deletions cli/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ packages:
dependency: "direct dev"
description:
name: lints
sha256: "4a16b3f03741e1252fda5de3ce712666d010ba2122f8e912c94f9f7b90e1a4c3"
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
url: "https://pub.dev"
source: hosted
version: "5.1.0"
version: "5.0.0"
logging:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion cli/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: supadart
description: Generate Dart classes from your Supabase schema.
version: 1.6.9
version: 1.7.0

repository: https://github.com/mmvergara/supadart
homepage: https://github.com/mmvergara/supadart
Expand Down
2 changes: 1 addition & 1 deletion cli/test/models/generated_classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension SupadartStorageClient on SupabaseStorageClient {}
// Enums
enum MOOD { happy, sad, neutral, excited, angry }

enum USERGROUP { users, admin, moderator }
enum USERGROUP { USERS, ADMIN, MODERATOR }

// Utils
extension DurationFromString on Duration {
Expand Down

0 comments on commit e27c0fd

Please sign in to comment.