Database interface design - was how to build up the library.

Adam Ruppe destructionator at gmail.com
Fri Oct 7 12:00:11 PDT 2011


Sean Kelly wote:
> Does your Row equate to the ResultSet above?

Fairly similar.

Mine looks something like this:

interface ResultSet {
        // name for associative array to result index
        int getFieldIndex(string field);
        string[] fieldNames();

        bool empty();
        Row front();
        void popFront();
        int length();
}

struct Row {
    // the actual column is returned as a string - probably should
    // change that, but mysql, postgres, and sqlite all offered that
    // and it works for me, so I went with it
    string opIndex(size_t idx) {}
    string opIndex(string columnName) {}
    int opApply(...) {}

    private string[] data;
}



Then, each of the database implementations use that little
ResultSet interface  to feed Row structs back to the user code.


More information about the Digitalmars-d mailing list