skelpo / CSV

A simple CSV file parser and serializer

Home Page:http://www.skelpo.codes/CSV/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Row handling in Parser?

daSkier opened this issue · comments

@calebkleveter I'm using CSV to load data into a database and I'm combining onHeader and onCell to effectively build a row dictionary. Do you think that is a common enough use case to merit including something like an onRow: handler in Parser.swift?

Maybe? If you are doing that it might be worth using the async CSVDecoder it will decode rows to a decodable type. I think that would handle a lot of the work for you. Plus if you have a custom type that represents your database model, you can just decode to that.

let decoder = CSVDecoder().async(for: [String: String], length 1024) { row in
    database.insert(row)
}

try decoder.decode(chunk)

Here are the API docs:

Closing due to inactivity. Feel free to re-open if you want to continue the discussion.