Qore DbDataProvider Module Reference  2.0
DbDataProvider.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
26 namespace DbDataProvider {
28 class DbDataProvider : public AbstractDataProvider {
29 
30 public:
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  };
48 
50  const ConstructorOptions = {
51  "datasource": <DataProviderOptionInfo>{
52  "type": (
53  AbstractDataProviderType::get(StringType),
54  AbstractDataProviderType::get(new Type("AbstractDatasource")),
55  ),
56  "desc": "the datasource connection string or an abstract datasource object",
57  },
58  "database": <DataProviderOptionInfo>{
59  "type": AbstractDataProviderType::get(new Type("AbstractDatabase")),
60  "desc": "the database for the object",
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 
99 protected:
101  AbstractDatabase db;
102 
104  static *code datasource_lookup;
105 
107  static *code table_lookup;
108 
109 public:
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 
173 protected:
174  *hash<string, AbstractDataField> getRecordTypeImpl(*hash<auto> search_options);
175 public:
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 
197 protected:
198  AbstractDataProviderRecordIterator searchRecordsImpl(*hash<auto> where_cond, *hash<auto> search_options);
199 public:
200 
201 
203  *list<hash<DataProviderSummaryInfo>> getChildProviderSummaryInfo();
204 
205 
207 
209 protected:
210  *list<string> getChildProviderNamesImpl();
211 public:
212 
213 
215 
221 protected:
222  *AbstractDataProvider getChildProviderImpl(string name);
223 public:
224 
225 
227 protected:
228  hash<DataProviderInfo> getStaticInfoImpl();
229 public:
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 
260 protected:
261  deleteChildProviderImpl(string name, *hash<auto> child_delete_options);
262 public:
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 };
*list< string > getChildProviderNamesImpl()
Returns a list of child data provider names, if any.
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.
*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.
hash< auto > makeTableDesc(string name, hash< string, AbstractDataField > fields, *hash< auto > opts)
Returns a table description hash from a field description.
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 setDatasourceLookup(code datasource_lookup)
Sets the datasource lookup.
static AbstractDatasource getDatasource(AbstractDatasource ds)
Returns the given AbstractDatasource object.
hash< DataProviderInfo > getStaticInfoImpl()
Returns data provider static info.
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
static hash< GenericColumnInfo > getColumnDesc(AbstractDatabase db, AbstractDataField field, *hash< auto > opts)
Returns a column description hash for a field.
*list< hash< DataProviderSummaryInfo > > getChildProviderSummaryInfo()
Return data provider summary info.
static AbstractDatasource getDatasource(string ds_string)
Returns an AbstractDatasource object from the given string.
static *hash< string, AbstractDataField > getRecordTypeFromDescribeHash(hash< auto > describe_hash)
Returns the record type description from a describe hash.
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
static setTableLookup(code table_lookup)
Sets the table lookup.
*hash< string, AbstractDataField > getRecordTypeImpl(*hash< auto > search_options)
Returns the description of the record type, if any.
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
const True
const NOTHING
Qore AbstractDbRecordIterator class definition.
Definition: AbstractDbRecordIterator.qc.dox.h:26