novi / mysql-swift

A type safe MySQL client for Swift
MIT License
163 stars 40 forks source link

Swift 4 Decodable pattern for basic queries #64

Closed patrick-zippenfenig closed 6 years ago

patrick-zippenfenig commented 7 years ago
struct User: Decodable {
  let id: Int
  let user_name: String
  let age: Int?
}
let rows: [User] =  try conn.query("SELECT id, user_name FROM users WHERE id = 123")

See https://github.com/novi/mysql-swift/issues/58. QueryRowResultType still supported.

novi commented 7 years ago

Thanks for the pull request. The API design looks good.

Could you write a test for this decodable support?

patrick-zippenfenig commented 6 years ago

@novi Basic tests seem to be fine. I implemented a first version of "Encodable" locally. It's a little bit more complicated then Decodable. I will start another PR for encoding

novi commented 6 years ago

@patrick-zippenfenig Thanks and the test is fine. I noticed that AutoincrementID is not yet decodable and Data (Blob) test is absent. But I will merge this PR for now. We could open another PR for that.