Qore DbDataProvider Module Reference 2.0.1
Loading...
Searching...
No Matches
DbDataProvider.qc.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
26namespace DbDataProvider {
28class DbDataProvider : public AbstractDataProvider {
29
30public:
32 const ProviderInfo = <DataProviderInfo>{
33 "type": "DbDataProvider",
34 "supports_read": True,
35 "supports_bulk_read": True,
36 "supports_children": True,
37 "constructor_options": ConstructorOptions,
38 "search_options": SearchOptions,
39 "create_options": NOTHING,
40 "upsert_options": NOTHING,
41 "child_create_options": ChildCreateOptions,
42 "transaction_management": True,
43 "has_record": True,
44 "record_requires_search_options": True,
45 "supports_child_create": True,
46 "supports_child_delete": True,
47 "children_can_support_apis": False,
48 "children_can_support_records": True,
49 "children_can_support_observers": False,
50 };
51
53 const ConstructorOptions = {
54 "datasource": <DataProviderOptionInfo>{
55 "type": (
56 AbstractDataProviderType::get(StringType),
57 AbstractDataProviderType::get(new Type("AbstractDatasource")),
58 ),
59 "desc": "the datasource connection string or an abstract datasource object",
60 "required": True,
61 },
62 };
63
65 const SearchOptions = {
66 "sql": <DataProviderOptionInfo>{
67 "type": AbstractDataProviderType::get(StringType),
68 "desc": "the raw SQL for the select statement",
69 "required": True,
70 },
71 "args": <DataProviderOptionInfo>{
72 "type": AbstractDataProviderType::get(AutoListType),
73 "desc": "any bind arguments for the select statement",
74 },
75 };
76
78 const ChildCreateOptions = {
79 "primary_key": <DataProviderOptionInfo>{
80 "type": AbstractDataProviderType::get("softlist<string>"),
81 "desc": "a list of column names for the primary key for the table; use `primary_key_name` to set the "
82 "name of the primary key constraint manually, otherwise a suitable name will be automatically "
83 "generated",
84 },
85 "primary_key_name": <DataProviderOptionInfo>{
86 "type": AbstractDataProviderType::get(StringType),
87 "desc": "the name of the primary key constraint; only used if `primary_key` is set",
88 },
89 "indexes": <DataProviderOptionInfo>{
90 "type": new DbIndexesDataType(),
91 "desc": "a hash of indexes keyed by index name",
92 },
93 "foreign_constraints": <DataProviderOptionInfo>{
94 "type": new DbForeignConstraintsDataType(),
95 "desc": "a hash of foreign constraints keyed by foreign constraint name",
96 },
97 };
98
99protected:
101 AbstractDatabase db;
102
104 static *code datasource_lookup;
105
107 static *code table_lookup;
108
109public:
110
112 constructor(AbstractDatasource ds, *hash<auto> opts);
113
114
116 constructor(AbstractDatabase db);
117
118
120 constructor(*hash<auto> options);
121
122
124 string getName();
125
126
128 *string getDesc();
129
130
132
140
141
143
149
150
152
158
159
161
166 static *hash<string, AbstractDataField> getRecordTypeFromDescribeHash(hash<auto> describe_hash);
167
169
173protected:
174 *hash<string, AbstractDataField> getRecordTypeImpl(*hash<auto> search_options);
175public:
176
177
179
186 private AbstractDataProviderBulkRecordInterface searchRecordsBulkImpl(int block_size = 1000,
187 *hash<auto> where_cond, *hash<auto> search_options) {
188 return new DbSelectBulkRecordInterface(block_size, db.getDatasource(), where_cond, search_options);
189 }
190
192
197protected:
198 AbstractDataProviderRecordIterator searchRecordsImpl(*hash<auto> where_cond, *hash<auto> search_options);
199public:
200
201
203 *list<hash<DataProviderSummaryInfo>> getChildProviderSummaryInfo();
204
205
207
209protected:
211public:
212
213
215
221protected:
222 *AbstractDataProvider getChildProviderImpl(string name);
223public:
224
225
227protected:
228 hash<DataProviderInfo> getStaticInfoImpl();
229public:
230
231
233
241 private AbstractDataProvider createChildProviderImpl(string name, hash<string, AbstractDataField> fields,
242 *hash<auto> child_create_options) {
243 hash<auto> table_desc = makeTableDesc(name, fields, child_create_options);
244 AbstractTable table = db.makeTable(name, table_desc);
245 DbTableTransactionHelper th(table);
246 th.create();
247 if (logger);
248
249 return new DbTableDataProvider(table, logger);
250 }
251
253
260protected:
261 deleteChildProviderImpl(string name, *hash<auto> child_delete_options);
262public:
263
264
266 static setDatasourceLookup(code datasource_lookup);
267
269 static setTableLookup(code table_lookup);
270
272 static AbstractDatasource getDatasource(AbstractDatasource ds);
273
275 static AbstractDatasource getDatasource(string ds_string);
276
278 static AbstractTable getTable(string ds_string, string table_string);
279
281 static AbstractTable getTable(AbstractDatasource ds, string table_string);
282
284 static hash<GenericColumnInfo> getColumnDesc(AbstractDatabase db, AbstractDataField field, *hash<auto> opts);
285
287
289 hash<auto> makeTableDesc(string name, hash<string, AbstractDataField> fields, *hash<auto> opts);
290
291};
292};
static *code datasource_lookup
Lookup to get an abstract datasource from a name.
Definition: DbDataProvider.qc.dox.h:104
static AbstractTable getTable(string ds_string, string table_string)
Returns an AbstractTable object from the given datasource and table strings.
beginTransaction()
Begins a transaction in the datasource.
commit()
Commits any transaction in progress in the datasource.
static *hash< string, AbstractDataField > getRecordTypeFromDescribeHash(hash< auto > describe_hash)
Returns the record type description from a describe hash.
*string getDesc()
Returns the data provider description.
AbstractDataProviderRecordIterator searchRecordsImpl(*hash< auto > where_cond, *hash< auto > search_options)
Returns an iterator for zero or more records matching the search options.
AbstractDatabase db
The database object.
Definition: DbDataProvider.qc.dox.h:101
static AbstractTable getTable(AbstractDatasource ds, string table_string)
Returns an AbstractTable object from the given datasource and table arguments.
private AbstractDataProvider createChildProviderImpl(string name, hash< string, AbstractDataField > fields, *hash< auto > child_create_options)
Creates a new child data provider and returns it after adding as a child.
Definition: DbDataProvider.qc.dox.h:241
static hash< GenericColumnInfo > getColumnDesc(AbstractDatabase db, AbstractDataField field, *hash< auto > opts)
Returns a column description hash for a field.
static setDatasourceLookup(code datasource_lookup)
Sets the datasource lookup.
static AbstractDatasource getDatasource(AbstractDatasource ds)
Returns the given AbstractDatasource object.
deleteChildProviderImpl(string name, *hash< auto > child_delete_options)
Deletes a child data provider.
*AbstractDataProvider getChildProviderImpl(string name)
Returns the given child provider or NOTHING if the given child is unknown.
private AbstractDataProviderBulkRecordInterface searchRecordsBulkImpl(int block_size=1000, *hash< auto > where_cond, *hash< auto > search_options)
Returns an iterator for zero or more records matching the search options.
Definition: DbDataProvider.qc.dox.h:186
constructor(AbstractDatasource ds, *hash< auto > opts)
creates the object
*list< string > getChildProviderNamesImpl()
Returns a list of child data provider names, if any.
hash< auto > makeTableDesc(string name, hash< string, AbstractDataField > fields, *hash< auto > opts)
Returns a table description hash from a field description.
static AbstractDatasource getDatasource(string ds_string)
Returns an AbstractDatasource object from the given string.
string getName()
Returns the data provider name.
static *code table_lookup
Lookup to get an abstract table from a datasource and a name.
Definition: DbDataProvider.qc.dox.h:107
constructor(AbstractDatabase db)
creates the object
*hash< string, AbstractDataField > getRecordTypeImpl(*hash< auto > search_options)
Returns the description of the record type, if any.
static setTableLookup(code table_lookup)
Sets the table lookup.
hash< DataProviderInfo > getStaticInfoImpl()
Returns data provider static info.
*list< hash< DataProviderSummaryInfo > > getChildProviderSummaryInfo()
Return data provider summary info.
constructor(*hash< auto > options)
Creates the object from constructor options.
rollback()
Rolls back any transaction in progress in the datasource.
The type definition for foreign constraints.
Definition: DbForeignConstraintsDataType.qc.dox.h:4
The type definition for DB indexes.
Definition: DbIndexesDataType.qc.dox.h:4
Defines the record iterator class for Table-based iterators.
Definition: DbSelectBulkRecordInterface.qc.dox.h:28
Defines a data provider based on a single SQL table.
Definition: DbTableDataProvider.qc.dox.h:28
Qore AbstractDbRecordIterator class definition.
Definition: AbstractDbRecordIterator.qc.dox.h:26