diff --git a/README.md b/README.md index a7197a2e2..a7b9ad59e 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,65 @@ Task { - Other Social Logins if using a webview will be similar to above and just follow the [Supabase's Documentation](https://supabase.com/docs/guides/auth/) for their setup +## Basic CRUD Implementation + +Import and Initialize the Supabase client + +```swift +let client = SupabaseClient(supabaseURL: "{ Supabase URL }", supabaseKey: "{ Supabase anonymous Key }") +``` + +### Insert Data + +Create a model which follows the data structure of your table. + +```swift +struct InsertModel: Encodable { + let id: Int? // you can choose to omit this depending on how you've setup your table + let title: String? + let desc: String? +} + +let insertData = InsertModel(title: "Test", desc: "Test Desc") +let query = client.database + .from("{ Your Table Name }") + .insert(values: insertData, + returning: .representation) // you will need to add this to return the added data + .select(columns: "id") // specifiy which column names to be returned. Leave it empty for all columns + .single() // specify you want to return a single value. + +Task { + do { + let response: InsertModel = try await query.execute().value + print("### Returned: \(response)") + } catch { + print("### Insert Error: \(error)") + } +} +``` + +### Select Data + +Using the same model as before + +```swift +let insertData = InsertModel(title: "Test", desc: "Test Desc") +let query = client.database + .from("{ Your Table Name }") + .select() // keep it empty for all, else specify returned data + .match(query: ["title" : insertData.title, "desc": insertData.desc]) + .single() + +Task { + do { + let response: InsertModel = try await query.execute().value + print("### Returned: \(response)") + } catch { + print("### Insert Error: \(error)") + } +} +``` + ## Contributing - Fork the repo on GitHub