Hi Earle,

> I've looked around for a CSV adapter, but haven't had any luck.  So I'm 
> thinking about writing my own.  Basically, it
> would be a wrapper around FasterCSV.  One issue that is (I think uniquely) 
> important with CSV files is the field order.
>   I'm thinking of using a :field_index property option to identify field 
> order.  One other option might be to use the
> order of property declaration to determine field order.

The convention with CSV files appears that the first line be the
header, with the names of each column.  Most useful CSV files I've
ever seen follow that convention because it can sometimes be almost
impossible to determine the purpose of a field without a header, at
least in non-trivial CSV files.

Just yesterday I was parsing a CSV file, and importing into some
DataMapper models, and the code to map the fields to the column was
pretty simple:

  http://gist.github.com/50671

> I'm also considering a :field_name option to identify the field name in the 
> header row, if any.

In a first draft I would just suggest making the header row required.

> Does anyone have any thoughts on these items or general thoughts about what a 
> CSV adapter ought to look like/do?
> If anyone has done any work in this area, pointers are welcome.

It would be nice if the full CRUD interface could be supported.  I
would take care not to load the entire CSV file into memory, and would
suggest processing it as a stream -- one line at a time, FasterCSV
makes this easy though. As you parse each line, you'll need to compare
it against the query conditions: see the InMemoryAdapter in dkubb/dm-
core for some examples of this, you will likely be able to use the
same code, it's very well tested.  After matching every row, you will
need to sort the results, and then slice them down if there is a limit/
offset.  All of this is solved in the InMemoryAdapter I mentioned, so
you can use it as a reference.

Dan
(dkubb)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to