1

In Firestore, a query for "array contains" is simple.

Firestore.firestore().collection("Posts").whereField("members", arrayContains: userid)

How can the same query be achieved in Supabase?

Getting all documents is not a problem, but I get a status code 400 when I try to filter by array contains.

let client = SupabaseClient(supabaseURL: URL(string: "****")!, supabaseKey: "*****")

        Task {
            do {
                let response: [tableModel] = try await client.database
                      .from("Posts")
                      .select("*")
                      .in(column: "members", value: [userid])
                      .execute().value
                
            } catch {
                print("### Insert Error: \(error)")
            }

Other attempts...

.from("Posts").select(columns: "*").filter(column: "members", operator: .cs, value: userid).execute().value
                    
.from("Posts").select(columns: "*").contains(column: "members", value: userid).execute().value

Is this not possible?

NexusUA
  • 217
  • 1
  • 3
  • 13
Redstain
  • 157
  • 2
  • 10
  • The very last attempt looks correct, but do you get an error? You should also see an error message if it throws an error, but what does the error message say? – dshukertjr May 05 '23 at 13:47
  • Error message is ---> ### Insert Error: unacceptableStatusCode(400). I also think it looks correct. In the database the array is a text[] and RLS is open for all CRUD requests. – Redstain May 05 '23 at 14:00
  • Supabase doesn't throw 400 errors for not finding any rows, but instead just return an empty array. One thing that I would try is to rename your table name to lower case like `posts` from `Posts`. If that doesn't do it, I would open an issue on the Supabase Swift github repo. – dshukertjr May 05 '23 at 15:12
  • I already renamed it to posts as i read that somewhere. Unfortunately it did not change anything. I'll open an issue. Thanks. – Redstain May 05 '23 at 15:22

0 Answers0