0
votes

I'm using https://github.com/stephencelis/SQLite.swift to implement SQLite in swift. I read through the documentation but couldn't find what's the return type for filter specifically here https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md#filtering-rows

The reason I'm asking is because I have a table called userTable containing all usernames, emails... of all users, but how can I lookup if a specific user exist?

For the filter function, I have no idea what Table.filter return type is if there is nothing found that's matching the condition.

Specifically if "bob01" is not in the table then what would
table.filter(username=="bob01") return?

Thanks!

1

1 Answers

0
votes

If you want to select data from table you can use "prepare" or "pluck" methods of library. When you write "table.filter(...)", you actually define a query. So you should give this query to one of the above functions. Different of these functions are return type. "Prepare" returns an Array includes Row type and "Pluck" returns Row. And finally, Row is a class that comes with SQLite.swift library.

let query = table.filter(username=="bob01")
var row = try db!.pluck(query)  //it's optional 

There is a video about it but it's in Turkish language: https://www.youtube.com/watch?v=cXA6ehpli5I

Also there is a part of code on my github: https://github.com/sercan5534/swift-lesson/blob/master/Swift-DB-Operations/SQLiteTest/DBUtil.swift