PostgREST

0.0.6

Swift client for PostgREST
supabase-community/postgrest-swift

What's New

0.0.6

2022-07-12T09:18:15Z

Changes

  • Fixes a bug introduced on 0.0.5

Full Changelog: 0.0.5...0.0.6

Postgrest Swift

Installation

Swift client for PostgREST. The goal of this library is to make an "ORM-like" restful interface.

Swift Package Manager

Add postgrest-swift as a dependency to your Package.swift file. For more information, please see the Swift Package Manager documentation.

.package(url: "https://github.com/supabase/postgrest-swift", .exact("0.0.4"))

Supabase

You can also install the supabase-swift package to use the entire supabase library.

Usage

import Foundation
import PostgREST

let supabaseUrl = ""
let supabaseKey = ""

var database = PostgrestClient(
    url: "\(supabaseUrl)/rest/v1",
    headers: ["apikey": supabaseKey],
    schema: "public")

struct Todo: Codable, Hashable {
  let id: UUID
  var description: String
  var isComplete: Bool

  enum CodingKeys: String, CodingKey {
    case id
    case description
    case isComplete = "is_complete"
  }
}

struct NewTodo: Codable, Hashable {
  var description: String
  var isComplete: Bool = false

  enum CodingKeys: String, CodingKey {
    case description
    case isComplete = "is_complete"
  }
}

// Get todos
var todos = try await client
    .from("todo")
    .select()
    .execute()
    .decoded(to: [Todo].self)

// Insert a todo
let insertedTodo = try await client.from("todo")
    .insert(values: NewTodo(description: "Implement integration tests for postgrest-swift"))
    .execute()
    .decoded(to: [Todo].self)[0]

// Insert multiple todos
let insertedTodos = try await client.from("todo")
    .insert(values: [
        NewTodo(description: "Make supabase swift libraries production ready"),
        NewTodo(description: "Drink some coffee"),
    ])
    .execute()
    .decoded(to: [Todo].self)

Contributing

  • Fork the repo on GitHub
  • Clone the project to your own machine
  • Commit changes to your own branch
  • Push your work back up to your fork
  • Submit a Pull request so that we can review your changes and merge

License

This repo is liscenced under MIT.

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Tue Sep 06 2022 07:27:41 GMT-0500 (GMT-05:00)