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  "required": True,
58  },
59  };
60 
62  const SearchOptions = {
63  "sql": <DataProviderOptionInfo>{
64  "type": AbstractDataProviderType::get(StringType),
65  "desc": "the raw SQL for the select statement",
66  "required": True,
67  },
68  "args": <DataProviderOptionInfo>{
69  "type": AbstractDataProviderType::get(AutoListType),
70  "desc": "any bind arguments for the select statement",
71  },
72  };
73 
75  const ChildCreateOptions = {
76  "primary_key": <DataProviderOptionInfo>{
77  "type": AbstractDataProviderType::get("softlist<string>"),
78  "desc": "a list of column names for the primary key for the table; use `primary_key_name` to set the "
79  "name of the primary key constraint manually, otherwise a suitable name will be automatically "
80  "generated",
81  },
82  "primary_key_name": <DataProviderOptionInfo>{
83  "type": AbstractDataProviderType::get(StringType),
84  "desc": "the name of the primary key constraint; only used if `primary_key` is set",
85  },
86  "indexes": <DataProviderOptionInfo>{
87  "type": new DbIndexesDataType(),
88  "desc": "a hash of indexes keyed by index name",
89  },
90  "foreign_constraints": <DataProviderOptionInfo>{
91  "type": new DbForeignConstraintsDataType(),
92  "desc": "a hash of foreign constraints keyed by foreign constraint name",
93  },
94  };
95 
96 protected:
98  AbstractDatabase db;
99 
101  static __7_ code datasource_lookup;
102 
104  static __7_ code table_lookup;
105 
106 public:
107 
109  constructor(AbstractDatasource ds, __7_ hash<auto> opts);
110 
111 
113  constructor(AbstractDatabase db);
114 
115 
117  constructor(__7_ hash<auto> options);
118 
119 
121  string getName();
122 
123 
125  __7_ string getDesc();
126 
127 
129 
137 
138 
140 
146 
147 
149 
155 
156 
158 
163  static __7_ hash<string, AbstractDataField> getRecordTypeFromDescribeHash(hash<auto> describe_hash);
164 
166 
170 protected:
171  __7_ hash<string, AbstractDataField> getRecordTypeImpl(__7_ hash<auto> search_options);
172 public:
173 
174 
176 
183  private AbstractDataProviderBulkRecordInterface searchRecordsBulkImpl(int block_size = 1000,
184  *hash<auto> where_cond, *hash<auto> search_options) {
185  return new DbSelectBulkRecordInterface(block_size, db.getDatasource(), where_cond, search_options);
186  }
187 
189 
194 protected:
195  AbstractDataProviderRecordIterator searchRecordsImpl(__7_ hash<auto> where_cond, __7_ hash<auto> search_options);
196 public:
197 
198 
200  __7_ list<hash<DataProviderSummaryInfo>> getChildProviderSummaryInfo();
201 
202 
204 
206 protected:
207  __7_ list<string> getChildProviderNamesImpl();
208 public:
209 
210 
212 
218 protected:
219  __7_ AbstractDataProvider getChildProviderImpl(string name);
220 public:
221 
222 
224 protected:
225  hash<DataProviderInfo> getStaticInfoImpl();
226 public:
227 
228 
230 
238  private AbstractDataProvider createChildProviderImpl(string name, hash<string, AbstractDataField> fields,
239  *hash<auto> child_create_options) {
240  hash<auto> table_desc = makeTableDesc(name, fields, child_create_options);
241  AbstractTable table = db.makeTable(name, table_desc);
242  DbTableTransactionHelper th(table);
243  th.create();
244  if (logger);
245 
246  return new DbTableDataProvider(table, logger);
247  }
248 
250 
257 protected:
258  deleteChildProviderImpl(string name, __7_ hash<auto> child_delete_options);
259 public:
260 
261 
263  static setDatasourceLookup(code datasource_lookup);
264 
266  static setTableLookup(code table_lookup);
267 
269  static AbstractDatasource getDatasource(AbstractDatasource ds);
270 
272  static AbstractDatasource getDatasource(string ds_string);
273 
275  static AbstractTable getTable(string ds_string, string table_string);
276 
278  static AbstractTable getTable(AbstractDatasource ds, string table_string);
279 
281  static hash<GenericColumnInfo> getColumnDesc(AbstractDatabase db, AbstractDataField field, __7_ hash<auto> opts);
282 
284 
286  hash<auto> makeTableDesc(string name, hash<string, AbstractDataField> fields, __7_ hash<auto> opts);
287 
288 };
289 };
__7_ list< string > getChildProviderNamesImpl()
Returns a list of child data provider names, if any.
static __7_ code datasource_lookup
Lookup to get an abstract datasource from a name.
Definition: DbDataProvider.qc.dox.h:101
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.
__7_ string getDesc()
Returns the data provider description.
AbstractDataProviderRecordIterator searchRecordsImpl(__7_ hash< auto > where_cond, __7_ 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, __7_ hash< auto > opts)
Returns a table description hash from a field description.
AbstractDatabase db
The database object.
Definition: DbDataProvider.qc.dox.h:98
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:238
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, __7_ hash< auto > child_delete_options)
Deletes a child data provider.
__7_ 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:183
constructor(AbstractDatasource ds, __7_ hash< auto > opts)
creates the object
static hash< GenericColumnInfo > getColumnDesc(AbstractDatabase db, AbstractDataField field, __7_ hash< auto > opts)
Returns a column description hash for a field.
__7_ list< hash< DataProviderSummaryInfo > > getChildProviderSummaryInfo()
Return data provider summary info.
static AbstractDatasource getDatasource(string ds_string)
Returns an AbstractDatasource object from the given string.
static __7_ 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 __7_ code table_lookup
Lookup to get an abstract table from a datasource and a name.
Definition: DbDataProvider.qc.dox.h:104
constructor(AbstractDatabase db)
creates the object
static setTableLookup(code table_lookup)
Sets the table lookup.
__7_ hash< string, AbstractDataField > getRecordTypeImpl(__7_ hash< auto > search_options)
Returns the description of the record type, if any.
constructor(__7_ 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