Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there some convenient ORM library framework for c?

Tags:

c

database

orm

I use sqlite3 with c language recently. Can anyone tell me some convenient ORM for c? Is there necessay to develop a ORM mechanism for my own projects?

like image 506
Yifan Wang Avatar asked May 14 '12 02:05

Yifan Wang


2 Answers

Having a need for ORM suggests to me that you have some sort of business / domain object model in mind that you want to map to a database.

If that is the case, then it strikes me that you are trying to write a business application in a language best suited for systems programming (C). You might want to consider whether this is a good architectural strategy.

Furthermore, I don't think ORM is ever likely to be a good fit for a language that:

  1. Isn't itself object-oriented
  2. Doesn't have much support for meta-programming / reflection which tends to be central to many ORM schemes

Finally, there are plenty of people who believe that ORM is an anti-pattern in any case. (example, example, example)

Overall, my suggestion would be to either:

  • Avoid ORM altogether if you plan to continue using C
  • Switch to a language / platform where ORM is at least well supported and fits the paradigm (most obviously Java)
like image 86
mikera Avatar answered Nov 12 '22 12:11

mikera


i wrote this library as an "ORM for C".

example code looks like:

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
}

unfortunately, it's not in use anywhere (as far as i know) and it includes quite a few ideas that seasoned c programmers might find odd. but it's not abandoned - i am still interested in the problem and hope to continue work on it at some point.

like image 39
andrew cooke Avatar answered Nov 12 '22 11:11

andrew cooke