Supabase Flutter Types? In web development, supabase provide you with an API to generate typescript types to make typesafe queries. But what about for flutter? for dart? That's what this is all about
Yes we can generate dart classes directly from you supabase schema in order to achieve Typesafe Queries Flutter Supabase
Supabase Schema Dart Class Generator using this tool you can generate dart class via WebApp or CLI
we now have a typesafe'ish to interact with the database.
Getting Table Name
Books.table_name// "books"
Fetch Data
// fetchedBooks is a typeof List<Books>finalbooks=awaitsupabase.books.select("*").withConverter((data)=>data.map(Books.fromJson).toList());
Insert Data
yes, we know which ones is required and which ones are optional
finaldata=Books.insert(name:'Learn Flutter',description:'Endless brackets and braces',price:2,);awaitsupabase.books.insert(data);
Inset Many Data
finalmany_data=[Books.insert(name:'Learn Minecraft',description:'Endless blocks and bricks',price:2,),Books.insert(name:'Description is optional',created_at:DateTime.now(),price:2,),];awaitsupabase.books.insert(many_data);
Update Data
finalnewData=Books.update(name:'New Book Name',);awaitsupabase.books.update(newData).eq(Books.c_id,1);
Delete Data
awaitsupabase.books.delete().eq(Books.c_id,1);
How it works is that it uses the rest api to fetch for your schemas and then constructs the dart classes for you. Is it safe? yes first of all the project is open source and they api is used by other tools like this one that visualizes your database.
Is this only for flutter? no you can use it in a normal Dart Project.
Im trying to make it better for the community i would really appreciate some help and suggestions to improve it. especially the process of parsing the data to dart types, but either way the generated classes are tested for runtime for most supabase / postgres types