supabase_typegen library

Generates typed Supabase table definitions, row extension types and column tokens from a database schema.

Classes

ColumnDescription
Description of a single table column.
ComputedFieldDescription
A computed field of a table: a function taking the table's row type and returning a scalar, which PostgREST selects like a column but leaves out of *.
ComputedRelationshipDescription
A computed relationship of a table: a function taking the table's row type and returning a row or a set of rows of targetTable, which PostgREST embeds like a foreign table.
DatabaseDescription
Description of the schemas of a database that types are generated for, the input to the code generator.
EnumDescription
Description of a Postgres enum type.
ForeignKeyDescription
The target of a foreign key column.
FunctionArgumentDescription
An input parameter of a FunctionOverloadDescription.
FunctionColumnsResult
The function returns rows of its own shape, RETURNS TABLE (…). Nothing on the catalog says whether a column can be NULL, so every column is nullable.
FunctionDescription
A function PostgREST exposes under /rpc, with its overloads.
FunctionNoResult
The function returns nothing (void).
FunctionOverloadDescription
One definition of a FunctionDescription.
FunctionResultDescription
What a call of a FunctionOverloadDescription returns.
FunctionTableRowsResult
The function returns rows of the described table schema.table, a list of them when isSetReturning and one row otherwise.
FunctionValueResult
The function returns a value of type, or a set of them when isSetReturning. A function can always return NULL, so the value is nullable whatever the type.
RelationshipDescription
A foreign key from sourceTable to targetTable.
TableDescription
Description of a table or view.
ValueTypeDescription
The Dart-relevant type of a function argument, a function result or an element of a set-returning function.

Enums

ColumnTypeKind
The Dart-relevant type of a column, derived from the Postgres type at parse time so that later stages never have to compare type name strings.

Constants

supportedSupabaseMajorVersion → const int
The first major version of supabase_flutter, supabase and postgrest whose API the generated code compiles against.

Properties

minimumLanguageVersion → Version
The lowest language version the generated code is valid for: the value types omit unset columns with null-aware map elements, which need Dart 3.8.
final

Functions

camelCase(String name) → String
Converts name to camelCase, for example created_at to createdAt.
formatWithSdk(String code, Version languageVersion, {String? path}) → Future<String?>
Formats code with the dart format of the Dart SDK running this program, for languageVersion, so the result is exactly what that formatter leaves unchanged in a project on that language version. With path, the path the code is written to, the formatter also applies the formatter settings of the analysis_options.yaml that governs that path, such as its page width.
generateDartCode(DatabaseDescription database, {String importUri = 'package:postgrest/postgrest.dart', Version? languageVersion}) → String
Generates a Dart source file with typed table definitions, row extension types, insert and update value types, column tokens, computed fields, relations, Postgres enums and typed function calls for the schemas of database.
memberIdentifier(String name) → String
Converts name to a valid Dart member identifier in camelCase.
packageImportUri({Directory? startDirectory}) → String
The library the generated code imports by default for the Dart package startDirectory belongs to, found through the same pubspec.yaml as packageLanguageVersion: the library of supabase_flutter, supabase or postgrest, preferred in that order, that the package lists under dependencies. Returns package:postgrest/postgrest.dart when it depends on none of them or no such pubspec exists.
packageLanguageVersion({Directory? startDirectory}) → Version?
The language version of the Dart package startDirectory belongs to, resolved the way dart format and the analyzer resolve it: the lower bound of the environment.sdk constraint in the pubspec.yaml of startDirectory, which defaults to the current directory, or of its nearest ancestor. Returns null when no such pubspec exists or it has no SDK constraint.
parseGeneratorMetadata(Map<String, dynamic> document, {List<String>? schemaNames}) → DatabaseDescription
Parses a GeneratorMetadata document, the introspection contract of @supabase/postgrest-typegen, into a DatabaseDescription of the schemas named in schemaNames, or of every schema the document lists when none are given. Named schemas the document does not list are left out.
pascalCase(String name) → String
Converts name to PascalCase, for example author_stats to AuthorStats.
snakeCase(String name) → String
Converts name to snake_case, for example mapByMood to map_by_mood.
unsupportedSupabaseDependency({Directory? startDirectory}) → (String, Version)?
The first of supabase_flutter, supabase and postgrest that the Dart package startDirectory belongs to resolves to a version before supportedSupabaseMajorVersion, with that version. The package is found through the same pubspec.yaml as packageLanguageVersion, and its versions are read from the pubspec.lock next to it, or next to the workspace root for a workspace member. Returns null when every one of them it resolves is supported, or when there is no such lockfile or it cannot be read.

Exceptions / Errors

GeneratorMetadataFormatException
Thrown when a document does not have the GeneratorMetadata shape.