Last active
December 5, 2022 21:24
-
-
Save matthewmorek/d88cf8c1c93503588016f5ff0875d29b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Link: Codable, Identifiable, Equatable, Hashable { | |
let id: UUID | |
var title: String | |
var url: URL | |
var description: String | |
var imageUrl: URL? | |
var category: LinkCategory? | |
enum CodingKeys: String, CodingKey { | |
case id | |
case title | |
case url | |
case description | |
case imageUrl = "image_url" | |
case category | |
} | |
init(id: UUID, title: String, url: URL, description: String, imageUrl: URL? = nil, category: LinkCategory? = nil/*, createdAt: Date*/) { | |
self.id = id | |
self.title = title | |
self.url = url | |
self.description = description | |
self.imageUrl = imageUrl | |
self.category = category | |
} | |
} | |
struct LinkCategory: Identifiable, Codable, Equatable, Hashable { | |
let id: UUID | |
var name: String | |
var description: String | |
init(id: UUID, name: String, description: String) { | |
self.id = id | |
self.name = name | |
self.description = description | |
} | |
} | |
// function to fetch all links and decode as appropriate types | |
mutating func getLinks() async -> [Link]? { | |
do { | |
// how do you use query builder to fetch replationships? | |
let response = try await client.database.from("links").select().execute() | |
let links = try response.decoded(to: [Link].self) | |
return links | |
} catch { | |
print(error) | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment