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 beNULL, 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,supabaseandpostgrestwhose 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
nameto camelCase, for examplecreated_attocreatedAt. -
formatWithSdk(
String code, Version languageVersion, {String? path}) → Future< String?> -
Formats
codewith thedart formatof the Dart SDK running this program, forlanguageVersion, so the result is exactly what that formatter leaves unchanged in a project on that language version. Withpath, the path the code is written to, the formatter also applies theformattersettings of theanalysis_options.yamlthat 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
nameto a valid Dart member identifier in camelCase. -
packageImportUri(
{Directory? startDirectory}) → String -
The library the generated code imports by default for the Dart package
startDirectorybelongs to, found through the samepubspec.yamlas packageLanguageVersion: the library ofsupabase_flutter,supabaseorpostgrest, preferred in that order, that the package lists underdependencies. Returnspackage:postgrest/postgrest.dartwhen it depends on none of them or no such pubspec exists. -
packageLanguageVersion(
{Directory? startDirectory}) → Version? -
The language version of the Dart package
startDirectorybelongs to, resolved the waydart formatand the analyzer resolve it: the lower bound of theenvironment.sdkconstraint in thepubspec.yamlofstartDirectory, which defaults to the current directory, or of its nearest ancestor. Returnsnullwhen no such pubspec exists or it has no SDK constraint. -
parseGeneratorMetadata(
Map< String, dynamic> document, {List<String> ? schemaNames}) → DatabaseDescription -
Parses a
GeneratorMetadatadocument, the introspection contract of@supabase/postgrest-typegen, into a DatabaseDescription of the schemas named inschemaNames, 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
nameto PascalCase, for exampleauthor_statstoAuthorStats. -
snakeCase(
String name) → String -
Converts
nameto snake_case, for examplemapByMoodtomap_by_mood. -
unsupportedSupabaseDependency(
{Directory? startDirectory}) → (String, Version)? -
The first of
supabase_flutter,supabaseandpostgrestthat the Dart packagestartDirectorybelongs to resolves to a version before supportedSupabaseMajorVersion, with that version. The package is found through the samepubspec.yamlas packageLanguageVersion, and its versions are read from thepubspec.locknext to it, or next to the workspace root for a workspace member. Returnsnullwhen 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
GeneratorMetadatashape.