Ferreteria/v2/usage/db: Difference between revisions
m (Woozle moved page Ferreteria/pieces/db to Ferreteria/usage/db: this should be a usage guide) |
m (7 revisions imported: moving this project here) |
||
| (3 intermediate revisions by one other user not shown) | |||
| Line 6: | Line 6: | ||
* The Factory creates the appropriate '''Connection''' object, passes it the rest of the spec to initialize it, and returns it to the caller. | * The Factory creates the appropriate '''Connection''' object, passes it the rest of the spec to initialize it, and returns it to the caller. | ||
==Files== | ==Files== | ||
Core classes: | |||
* {{ferreteria/code|db/db.php}} | * {{ferreteria/code|db/v2/db.php}} | ||
* {{ferreteria/code|db/db-conn.php}} | * {{ferreteria/code|db/v2/db-conn.php}}: abstract database engine | ||
* {{ferreteria/code|db/db- | ** {{ferreteria/code|db/v2/db-conn-mysqli.php}}: implementation for mysqli library | ||
* {{ferreteria/code|db/db- | * tables: | ||
** {{ferreteria/code|db/v2/tables/db-table.php}}: classes for basic table functionality | |||
** {{ferreteria/code|db/v2/tables/db-table-keyed.php}}: tables with one or more unique key fields | |||
* records: | |||
** {{ferreteria/code|db/v2/records/db-records.php}}: classes for basic recordset functionality (may or may not be attached to a table) | |||
** {{ferreteria/code|db/v2/records/db-records-keyed.php}}: records that self-identify with one or more unique key fields (can be updated in table) | |||
Helpers: | |||
* {{ferreteria/code|db/v2/db-ui.php}}: trait which adds support for admin interface functionality | |||
This is only a partial list, but includes some of the most heavily-used files. | |||
==Classes== | ==Classes== | ||
===primary=== | ===primary=== | ||
* '''fcDBOFactory''' | * '''fcDBOFactory''': static class for creating connections | ||
* '''fcDataEngine''' | * '''fcDataEngine''': handler for a particular type of database | ||
* '''fcDataConn''' | * '''fcDataConn''': connection to a database | ||
== | ==Notes== | ||
'''2017-09-15''' There's been some issue around the formatting of recordset fields. Tentatively, the only way to be consistent without requiring a lot of extra helper code that would be unnecessary most of the time is to assume they will be in the same format as the database, e.g. a BIT field will be asc(0) or asc(1) and needs to have conversion-{to/from}-boolean methods if it's going to be used as such. Database format is referred to as "stored", and simplest-calculable-internal representation (e.g. for dates, typically UNIX integer seconds since epoch, though there are other date formats requiring different representations) is referred to as "native". | |||
Latest revision as of 16:45, 22 May 2022
About
Databases in Ferreteria are managed through several sets of classes that work together. I am in the process of rewriting this module from scratch; information about the existing code is in /v1.
Rules
- Each Connection should be requested from the static DBO Factory class by passing it a connection spec.
- The Factory looks up which Connection class is needed for the type specified in the connection spec.
- The Factory creates the appropriate Connection object, passes it the rest of the spec to initialize it, and returns it to the caller.
Files
Core classes:
- Template:Ferreteria/code
- Template:Ferreteria/code: abstract database engine
- Template:Ferreteria/code: implementation for mysqli library
- tables:
- Template:Ferreteria/code: classes for basic table functionality
- Template:Ferreteria/code: tables with one or more unique key fields
- records:
- Template:Ferreteria/code: classes for basic recordset functionality (may or may not be attached to a table)
- Template:Ferreteria/code: records that self-identify with one or more unique key fields (can be updated in table)
Helpers:
- Template:Ferreteria/code: trait which adds support for admin interface functionality
This is only a partial list, but includes some of the most heavily-used files.
Classes
primary
- fcDBOFactory: static class for creating connections
- fcDataEngine: handler for a particular type of database
- fcDataConn: connection to a database
Notes
2017-09-15 There's been some issue around the formatting of recordset fields. Tentatively, the only way to be consistent without requiring a lot of extra helper code that would be unnecessary most of the time is to assume they will be in the same format as the database, e.g. a BIT field will be asc(0) or asc(1) and needs to have conversion-{to/from}-boolean methods if it's going to be used as such. Database format is referred to as "stored", and simplest-calculable-internal representation (e.g. for dates, typically UNIX integer seconds since epoch, though there are other date formats requiring different representations) is referred to as "native".