processwire-requests icon indicating copy to clipboard operation
processwire-requests copied to clipboard

Add getColumns method to WireDatabasePDO class

Open kiwigringo opened this issue 4 years ago • 0 comments

Add getColumns method to WireDatabasePDO class

class currently has the methods getTables tableExists

and

columnExists

but there is no analogue to getTables for columns.

The columnExists method already uses the SHOW COLUMNS FROM $table SQL statement, so it wouldn't take much to add another method that returns an array of columns in a given table.

Once implemented it will be possible to call:

$database->getColumns($table)

Why would the enhancement be useful to users?

Although ProcessWire itself probably doesn't need this method, it would be a useful method for working with custom database tables. A scenario where it would be useful would be to map ProcessWire inputfields to fields in a custom database table via the admin UI. If it's possible to retrieve a list of fields for a custom table, and their types, then it would be relatively straightforward to map them to compatible inputfields to build an admin UI to edit data. While it would be possible to do all of this in a custom module, since getColumns already has an analogue with getTables in the core, it would seem like this would be the most logical place to have this method, so that different third party modules that work with custom table data don't each have to create their own implementation.

kiwigringo avatar Nov 28 '21 20:11 kiwigringo