Clone wiki

c-orm / Home


What Does C-ORM Do?

C-ORM moves data between structs in C and tables in a relational
database (ie "in SQL"). It's a little like
Hibernate for Java, or
SQLAlchemy for Python - it simplifies
building structs from the data in the database, and also helps writing
data in structs back out again.

Here's a quick example:

    typedef struct person {
      int id;
      char *name;
    } person;

    void find_by_name(isti_db *db, const char *text, person** result) {
      corm_person_select *s;
      corm_person_select_alloc(&s, db);
      s->name(s, "like", text)->_go_one(s, result);  // populate result from the database
      s->_free(s, 0);  // in "real" code, 0 is a chained status value

Where corm_person_select etc were generated by C-ORM. You can see (I hope)
that this is searching for a person with a given name. The found instance
is returned in result. For much more detail, with full error handling,
please see the examples.

To do all this, C-ORM uses two things: a set of lower-level libraries
and a small Python script to generate code for specific structs.

You can also use C-ORM just for the lower-level libraries, without
using the Python script. Those libraries include support for SQL,
strings and arrays.

What Are C-ORM's Main Limitations?

  • It's very much in beta right now. The basic functionality is there
    (although no sugar for updates, only int and char * data types,
    and only SQLite support), but the packaging and documentation leave
    a lot to be desired.

  • It's very simple. There is no support for joins or collections of
    related structs, for example, which are basic parts of Hibernate and
    SQLAlchemy. This is partly by design, and partly because
    implementing something like that in C (not C++!) would be quite

  • At the same time, some people might find C-ORM's approach too
    complex. Auto-generated C code, via Python and pre-processor
    macros, is fairly opaque. On the other hand, that work is done, and
    hidden away in the library - the code that uses C-ORM can be simple
    and transparent.

  • C-ORM was written to make non-critical, medium-sized projects
    easier. It has not been pushed to extremes of scale and does not
    try to be terribly efficient (in speed or space). People are often
    working in C because they face strong constraints, but C-ORM was not
    written with those cases in mind. Having said that, it may still be
    useful, and I am always happy to consider patches that improve
    behaviour - feel free to contact me if
    you have more questions.

For a more positive view, see Architecture and Coding

Where Can I Learn More?

Start with the documentation here.