Debian Codegraph @

include/groonga/db.h

raw symbols SCIP
1 /*
2 Copyright(C) 2009-2018 Brazil
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #pragma once
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 typedef struct _grn_db_create_optarg grn_db_create_optarg;
26
27 struct _grn_db_create_optarg {
28 char **builtin_type_names;
29 int n_builtin_type_names;
30 };
31
32 /**
33 * \brief Create new database.
34 *
35 * \param ctx The context object.
36 * \param path File path of the database. Temporary database if `NULL` is
37 * specified.
38 * \param optarg Currently, it is not used. It is just ignored.
39 *
40 * \return The database on success, `NULL` on error.
41 */
42 GRN_API grn_obj *
43 grn_db_create(grn_ctx *ctx, const char *path, grn_db_create_optarg *optarg);
44
45 #define GRN_DB_OPEN_OR_CREATE(ctx, path, optarg, db) \
46 (((db) = grn_db_open((ctx), (path))) || \
47 (db = grn_db_create((ctx), (path), (optarg))))
48
49 /**
50 * \brief Open the database.
51 *
52 * \param ctx The context object.
53 * \param path File path of the database.
54 *
55 * \return The database on success, `NULL` on error.
56 */
57 GRN_API grn_obj *
58 grn_db_open(grn_ctx *ctx, const char *path);
59 /**
60 * \brief Update the last modified time of db to the current time.
61 * The last modified time is used, for example, to verify whether the
62 * cache is valid or not.
63 *
64 * \param ctx The context object.
65 * \param db The database.
66 */
67 GRN_API void
68 grn_db_touch(grn_ctx *ctx, grn_obj *db);
69 /**
70 * \brief Check the passed database and recover it if it is broken and it
71 * can be recovered.
72 *
73 * This API uses lock existence for checking whether the database is
74 * broken or not.
75 *
76 * Here are recoverable cases:
77 *
78 * - Index column is broken. The index column must have source column.
79 *
80 * Here are unrecoverable cases:
81 *
82 * - Object name management feature is broken.
83 * - Table is broken.
84 * - Data column is broken.
85 *
86 * Object name management feature is used for managing table name,
87 * column name and so on. If the feature is broken, the database can't
88 * be recovered. Please re-create the database from backup.
89 *
90 * Table and data column can be recovered manually by removing an existence
91 * lock and re-add data.
92 *
93 * \attention This is a dangerous API. You must not use this API when other
94 * thread or process opens the target database. If you use this API
95 * against shared database, the database may be broken.
96 *
97 * \since 4.0.9
98 *
99 * \param ctx The context object.
100 * \param db The database to be recovered.
101 *
102 * \return \ref GRN_SUCCESS on success, the appropriate \ref grn_rc on error.
103 */
104 GRN_API grn_rc
105 grn_db_recover(grn_ctx *ctx, grn_obj *db);
106 /**
107 * \brief Unmaps all opened tables and columns in the passed database.
108 * Resources used by these opened tables and columns are freed.
109 * Normally, this API is needless. Because resources used by opened
110 * tables and columns are managed by OS automatically.
111 *
112 * \attention This is a thread unsafe API. You can't touch the database while
113 * this API is running.
114 *
115 * \since 5.0.7
116 *
117 * \param ctx The context object.
118 * \param db The database to be unmaped.
119 *
120 * \return \ref GRN_SUCCESS on success, the appropriate \ref grn_rc on error.
121 */
122 GRN_API grn_rc
123 grn_db_unmap(grn_ctx *ctx, grn_obj *db);
124 GRN_API uint32_t
125 grn_db_get_last_modified(grn_ctx *ctx, grn_obj *db);
126 GRN_API bool
127 grn_db_is_dirty(grn_ctx *ctx, grn_obj *db);
128 GRN_API grn_rc
129 grn_db_set_cache(grn_ctx *ctx, grn_obj *db, grn_cache *cache);
130 GRN_API grn_cache *
131 grn_db_get_cache(grn_ctx *ctx, grn_obj *db);
132
133 #define GRN_DB_EACH_BEGIN_FLAGS(ctx, cursor, id, flags) \
134 GRN_TABLE_EACH_BEGIN_FLAGS(ctx, grn_ctx_db((ctx)), cursor, id, flags)
135
136 #define GRN_DB_EACH_BEGIN_BY_ID(ctx, cursor, id) \
137 GRN_DB_EACH_BEGIN_FLAGS(ctx, \
138 cursor, \
139 id, \
140 GRN_CURSOR_BY_ID | GRN_CURSOR_ASCENDING)
141
142 #define GRN_DB_EACH_BEGIN_BY_KEY(ctx, cursor, id) \
143 GRN_DB_EACH_BEGIN_FLAGS(ctx, \
144 cursor, \
145 id, \
146 GRN_CURSOR_BY_KEY | GRN_CURSOR_ASCENDING)
147
148 #define GRN_DB_EACH_END(ctx, cursor) GRN_TABLE_EACH_END(ctx, cursor)
149
150 #ifdef __cplusplus
151 }
152 #endif