libcmdbm 0.2.0
MyBatis-like SQL mapping library for C99
Loading...
Searching...
No Matches
libcmdbm.h
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2020 Dennis Soungjin Park<xcomart@gmail.com>
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23 */
24
101#ifndef LIBCMDBM_H__
102#define LIBCMDBM_H__
103
104#ifdef __cplusplus
105extern "C" {
106#endif
107
108#include <libcmutils.h>
109
110#ifndef CMDBM_API
111# if defined(MSWIN)
112# if defined(CMDBM_EXPORT)
113# define CMDBM_API __declspec(dllexport)
114# else
115# define CMDBM_API __declspec(dllimport)
116# endif
117# else
118# define CMDBM_API
119# endif
120#endif
121
122
136CMDBM_API const char *CMDBM_GetLibVersion(void);
137
153CMDBM_API void CMDBM_Init(void);
154
165CMDBM_API void CMDBM_Clear(void);
166
223 void (*LibraryInit)(void);
224
232 void (*LibraryClear)(void);
233
246 const char *(*GetDBMSKey)(void);
247
264 void *(*Initialize)(const char *dbcs, const char *prcs);
265
274 void (*CleanUp)(
275 void *initres);
276
293 char *(*GetBindString)(
294 void *initres,
295 uint32_t index,
296 char *buffer,
297 CMJsonValueType vtype);
298
310 const char *(*GetTestQuery)(void);
311
325 void *(*OpenConnection)(
326 void *initres,
327 CMUTIL_JsonObject *params);
328
336 void *initres,
337 void *connection);
338
350 void *initres,
351 void *connection);
352
364 void *initres,
365 void *connection);
366
375 void *initres,
376 void *connection);
377
385 void *initres,
386 void *connection);
387
404 CMUTIL_JsonValue *(*GetOneValue)(
405 void *initres,
406 void *connection,
407 CMUTIL_String *query,
408 CMUTIL_JsonArray *binds,
409 CMUTIL_JsonObject *outs);
410
425 CMUTIL_JsonObject *(*GetRow)(
426 void *initres,
427 void *connection,
428 CMUTIL_String *query,
429 CMUTIL_JsonArray *binds,
430 CMUTIL_JsonObject *outs);
431
445 CMUTIL_JsonArray *(*GetList)(
446 void *initres,
447 void *connection,
448 CMUTIL_String *query,
449 CMUTIL_JsonArray *binds,
450 CMUTIL_JsonObject *outs);
451
466 int (*Execute)(
467 void *initres,
468 void *connection,
469 CMUTIL_String *query,
470 CMUTIL_JsonArray *binds,
471 CMUTIL_JsonObject *outs);
472
493 void *(*OpenCursor)(
494 void *initres,
495 void *connection,
496 CMUTIL_String *query,
497 CMUTIL_JsonArray *binds,
498 CMUTIL_JsonObject *outs,
499 uint32_t fetchsize);
500
506 void (*CloseCursor)(
507 void *cursor);
508
516 CMUTIL_JsonObject *(*CursorNextRow)(
517 void *cursor);
518};
519
535CMDBM_API CMBool CMDBM_RegisterDBMS(
536 const char *dbmskey,
537 CMDBM_ModuleInterface *modif);
538
561typedef struct CMDBM_PoolConfig {
568 uint32_t pingterm;
578 CMBool pingtest;
591 uint32_t initcnt;
594 uint32_t maxcnt;
603 char *testsql;
605
609typedef struct CMDBM_Database CMDBM_Database;
624 CMBool (*AddMapper)(
625 CMDBM_Database *db,
626 const char *mapperfile);
627
642 CMBool (*AddMapperSet)(
643 CMDBM_Database *db,
644 const char *basepath,
645 const char *filepattern,
646 CMBool recursive);
647
659 CMBool (*SetMonitor)(
660 CMDBM_Database *db,
661 int interval);
662
672 void (*Destroy)(
673 CMDBM_Database *db);
674};
675
700 const char *sourceid,
701 const char *dbmskey,
702 const char *dbcharset,
703 CMDBM_PoolConfig *poolconf,
704 CMUTIL_JsonObject *params);
705
734typedef struct CMDBM_Session CMDBM_Session;
751 CMDBM_Session *session);
752
762 CMDBM_Session *session);
763
779 int (*Execute)(
780 CMDBM_Session *session,
781 const char *dbid,
782 const char *sqlid,
783 CMUTIL_JsonObject *params);
784
798 CMUTIL_JsonValue *(*GetObject)(
799 CMDBM_Session *session,
800 const char *dbid,
801 const char *sqlid,
802 CMUTIL_JsonObject *params);
803
814 CMUTIL_JsonObject *(*GetRow)(
815 CMDBM_Session *session,
816 const char *dbid,
817 const char *sqlid,
818 CMUTIL_JsonObject *params);
819
834 CMUTIL_JsonArray *(*GetRowSet)(
835 CMDBM_Session *session,
836 const char *dbid,
837 const char *sqlid,
838 CMUTIL_JsonObject *params);
839
863 CMBool (*ForEachRow)(
864 CMDBM_Session *session,
865 const char *dbid,
866 const char *sqlid,
867 CMUTIL_JsonObject *params,
868 void *udata,
869 CMBool (*rowcb)(
870 CMUTIL_JsonObject *row,
871 uint32_t rownum,
872 void *udata));
873
881 CMBool (*Commit)(
882 CMDBM_Session *session);
883
890 void (*Rollback)(
891 CMDBM_Session *session);
892
901 void (*Close)(
902 CMDBM_Session *session);
903};
904
920typedef struct CMDBM_Context CMDBM_Context;
938 CMBool (*AddDatabase)(
939 CMDBM_Context *context,
940 CMDBM_Database *database);
941
952 CMDBM_Session *(*GetSession)(
953 CMDBM_Context *context);
954
963 void (*Destroy)(
964 CMDBM_Context *context);
965};
966
988 const char *confjson,
989 const char *progcharset,
990 CMUTIL_Timer *timer);
991
996#ifdef __cplusplus
997}
998#endif
999
1000#endif // LIBCMDBM_H__
const char * CMDBM_GetLibVersion(void)
Version of the library which is being run.
void CMDBM_Init(void)
Initialize the library.
void CMDBM_Clear(void)
Release everything the library holds.
CMDBM_Context * CMDBM_ContextCreate(const char *confjson, const char *progcharset, CMUTIL_Timer *timer)
Create a context, optionally from a configuration file.
CMDBM_Database * CMDBM_DatabaseCreate(const char *sourceid, const char *dbmskey, const char *dbcharset, CMDBM_PoolConfig *poolconf, CMUTIL_JsonObject *params)
Build a datasource in code.
CMBool CMDBM_RegisterDBMS(const char *dbmskey, CMDBM_ModuleInterface *modif)
Make a DBMS module available under a name.
The root object: the datasources of an application and the sessions which use them.
Definition libcmdbm.h:921
CMBool(* AddDatabase)(CMDBM_Context *context, CMDBM_Database *database)
Start a datasource and take it over.
Definition libcmdbm.h:938
void(* Destroy)(CMDBM_Context *context)
Destroy the context and every datasource in it.
Definition libcmdbm.h:963
A datasource: one database, its pool and its statements.
Definition libcmdbm.h:610
CMBool(* AddMapperSet)(CMDBM_Database *db, const char *basepath, const char *filepattern, CMBool recursive)
Load every mapper file matching a pattern.
Definition libcmdbm.h:642
CMBool(* AddMapper)(CMDBM_Database *db, const char *mapperfile)
Load one mapper file into this datasource.
Definition libcmdbm.h:624
CMBool(* SetMonitor)(CMDBM_Database *db, int interval)
How often the mapper files are checked for changes.
Definition libcmdbm.h:659
void(* Destroy)(CMDBM_Database *db)
Destroy the datasource, closing every connection it pooled.
Definition libcmdbm.h:672
The set of callbacks a DBMS module implements.
Definition libcmdbm.h:211
CMBool(* StartTransaction)(void *initres, void *connection)
Begin a transaction on one connection.
Definition libcmdbm.h:349
CMBool(* CommitTransaction)(void *initres, void *connection)
Commit the running transaction.
Definition libcmdbm.h:374
void(* CloseConnection)(void *initres, void *connection)
Close a connection OpenConnection opened.
Definition libcmdbm.h:335
void(* LibraryInit)(void)
Prepare the client library, once per process.
Definition libcmdbm.h:223
int(* Execute)(void *initres, void *connection, CMUTIL_String *query, CMUTIL_JsonArray *binds, CMUTIL_JsonObject *outs)
Run a statement for its effect.
Definition libcmdbm.h:466
void(* CleanUp)(void *initres)
Release the context Initialize created.
Definition libcmdbm.h:274
void(* RollbackTransaction)(void *initres, void *connection)
Roll the running transaction back.
Definition libcmdbm.h:384
void(* EndTransaction)(void *initres, void *connection)
End the transaction StartTransaction began.
Definition libcmdbm.h:363
void(* LibraryClear)(void)
Release what LibraryInit prepared.
Definition libcmdbm.h:232
void(* CloseCursor)(void *cursor)
Close a cursor and release what it holds.
Definition libcmdbm.h:506
How a datasource pools its connections.
Definition libcmdbm.h:561
uint32_t pingterm
Seconds between two rounds of the idle connection check.
Definition libcmdbm.h:568
CMBool testonborrow
Whether a connection is validated when it is borrowed.
Definition libcmdbm.h:589
char * testsql
The statement which validates a connection.
Definition libcmdbm.h:603
CMBool pingtest
Whether idle connections are checked every pingterm seconds.
Definition libcmdbm.h:578
uint32_t initcnt
Connections opened when the datasource starts up.
Definition libcmdbm.h:591
uint32_t maxcnt
Upper limit of open connections. A session which asks for one beyond it waits, and gives up after fiv...
Definition libcmdbm.h:594
A session: the object statements are run through.
Definition libcmdbm.h:735
void(* Close)(CMDBM_Session *session)
Return the borrowed connections and destroy the session.
Definition libcmdbm.h:901
void(* EndTransaction)(CMDBM_Session *session)
Put the connections of this session back into autocommit.
Definition libcmdbm.h:761
CMBool(* ForEachRow)(CMDBM_Session *session, const char *dbid, const char *sqlid, CMUTIL_JsonObject *params, void *udata, CMBool(*rowcb)(CMUTIL_JsonObject *row, uint32_t rownum, void *udata))
Run a select and hand its rows to a callback one by one.
Definition libcmdbm.h:863
CMBool(* Commit)(CMDBM_Session *session)
Commit the running transaction on every connection of this session.
Definition libcmdbm.h:881
int(* Execute)(CMDBM_Session *session, const char *dbid, const char *sqlid, CMUTIL_JsonObject *params)
Run a statement for its effect.
Definition libcmdbm.h:779
void(* Rollback)(CMDBM_Session *session)
Roll the running transaction back on every connection of this session.
Definition libcmdbm.h:890
CMBool(* BeginTransaction)(CMDBM_Session *session)
Start a transaction across every datasource this session uses.
Definition libcmdbm.h:750