Is there any convenient ORM library structure for c?

I am using sqlite3 with c language recently. Can someone tell me some convenient ORM for c? Is there a need to develop an ORM mechanism for my own projects?

+6
source share
3 answers

Having the need for ORM, it seems to me that you have some kind of business model for the business / domain that you want to map to the database.

If so, then it seems to me that you are trying to write a business application in the language most suitable for system programming (C). Perhaps you should consider whether this is a good architectural strategy.

In addition, I do not think that ORM will always be suitable for a language that:

  • Not object oriented
  • It does not have much support for metaprogramming / reflection, which tends to be central to many ORM schemes.

Finally, there are many people who believe that ORM is an anti-pattern anyway. ( example , example , example )

Overall, my suggestion would be either:

  • Avoid ORM at all if you plan to continue using C
  • Switch to a language / platform where ORM is at least well supported and consistent with a paradigm (most obviously Java)
+2
source

I wrote this library as "ORM for C".

An example code looks like this:

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 is not used anywhere (as far as I know), and there are many ideas in it that seasoned programmers might find strange. but it is not left - I am still interested in the problem and hope to continue working on it at some point.

+3
source

In a brief Google search, the following appeared: http://ales.jikos.cz/smorm/

I never used it, so don't blame me if it reformatts all your hard drives and makes your refrigerator warm enough to spoil your milk, but it looks like it could be better than nothing if you really don't want to write queries.

0
source

Source: https://habr.com/ru/post/915626/


All Articles