2021/11/08/data objects refactoring: Difference between revisions
No edit summary |
mNo edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
I'm making some changes to the {{l/ferreteria/|v0.5/data | {{nav/codeblog}} | ||
[[category:ferreteria]] | |||
I'm making some changes to the {{l/ferreteria/|v0.5/data|data objects management system}} for {{hashtag|Ferreteria}} {{l/ferreteria/|v0.5}}. | |||
==at present== | ==at present== | ||
Database instantiation is currently done by <code>cDatabase::Instantiate()</code>, which uses an internal static table to look up the <code>cDatabase</code>-descendant to instantiate from a slug returned by <code>cDatabaseSpec->GetTypeString()</code>. | Database instantiation is currently done by <code>cDatabase::Instantiate()</code>, which uses an internal static table to look up the <code>cDatabase</code>-descendant to instantiate from a slug returned by <code>cDatabaseSpec->GetTypeString()</code>. | ||
Line 7: | Line 9: | ||
* <code>cDatabaseSpec</code> can instantiate directly, e.g. <code>cMainDBSpec->MakeDatabase()</code>. | * <code>cDatabaseSpec</code> can instantiate directly, e.g. <code>cMainDBSpec->MakeDatabase()</code>. | ||
* <code>cDatabase</code> should be named <code>caDatabase</code>, {{l/ferreteria/|coding|because}} it is abstract. | * <code>cDatabase</code> should be named <code>caDatabase</code>, {{l/ferreteria/|coding|because}} it is abstract. | ||
Also, Database-spec-class registration is currently done in <code>ferreteria/data/db/0.php</code>. This made some sense as a stopgap when I wasn't trying to properly handle app-specific databases or db-less tables, but that needs to change. | |||
==TO DO== | ==TO DO== | ||
* rename <code>cDatabase</code> to <code>caDatabase</code> | * rename <code>cDatabase</code> to <code>caDatabase</code> | ||
Line 12: | Line 16: | ||
* replace abstract <code>caDataSpec->GetTypeString()</code> method with <code>caDatabaseSpec->GetDatabaseClass()</code> | * replace abstract <code>caDataSpec->GetTypeString()</code> method with <code>caDatabaseSpec->GetDatabaseClass()</code> | ||
* write <code>caDatabaseSpec->MakeDatabase()</code> | * write <code>caDatabaseSpec->MakeDatabase()</code> | ||
* remove <code>caDatabase->Instantiate()</code> | |||
* add Database registry to <code>csObjects</code>: | |||
** AddDatabase(string $sSlug, caDatabase $db) | |||
** GetDatabase(string $sSlug) : caDatabase | |||
* registration of DB-spec classes should happen in a portable overrideable config file -- perhaps in <code>cConfigWeb</code>, in <code>ferreteria/config/portable/defaults.php</code>? | |||
Note that the same database can (and probably should) be registered until multiple names, for easier separation of roles. For example, if the main database is the default database for application tables and also contains the user-access tables, then it could be registered as "*" (default), "main", and "users". |
Latest revision as of 00:05, 2 July 2022
I'm making some changes to the data objects management system for #Ferreteria v0.5.
at present
Database instantiation is currently done by cDatabase::Instantiate()
, which uses an internal static table to look up the cDatabase
-descendant to instantiate from a slug returned by cDatabaseSpec->GetTypeString()
.
I suddenly realized that this makes no sense:
- the cDatabaseSpec-descendant should just return the class it wants to use, from
->GetDatabaseClass()
cDatabaseSpec
can instantiate directly, e.g.cMainDBSpec->MakeDatabase()
.cDatabase
should be namedcaDatabase
, because it is abstract.
Also, Database-spec-class registration is currently done in ferreteria/data/db/0.php
. This made some sense as a stopgap when I wasn't trying to properly handle app-specific databases or db-less tables, but that needs to change.
TO DO
- rename
cDatabase
tocaDatabase
- rename
cDatabaseSpec
tocaDatabaseSpec
- replace abstract
caDataSpec->GetTypeString()
method withcaDatabaseSpec->GetDatabaseClass()
- write
caDatabaseSpec->MakeDatabase()
- remove
caDatabase->Instantiate()
- add Database registry to
csObjects
:- AddDatabase(string $sSlug, caDatabase $db)
- GetDatabase(string $sSlug) : caDatabase
- registration of DB-spec classes should happen in a portable overrideable config file -- perhaps in
cConfigWeb
, inferreteria/config/portable/defaults.php
?
Note that the same database can (and probably should) be registered until multiple names, for easier separation of roles. For example, if the main database is the default database for application tables and also contains the user-access tables, then it could be registered as "*" (default), "main", and "users".