[Dbix-class] Naming conventions

Darren Duncan darren at darrenduncan.net
Sun Dec 27 04:39:11 GMT 2009


lbmlist at hethcote.com wrote:
> Is there a good reference for SQL naming conventions for use with 
> DBIx::Class?
> 
> Any pointers appreciated

The general rule of thumb for naming things in your SQL database is to do it the 
same way as you do in your applications, since SQL has a lot in common with 
normal programming languages like Perl, with everything basically being values, 
variables and types and routines.

A SQL database or a SQL schema is like a Perl package, that contains both 
package-name-qualified global variables and routine and type definitions, except 
that you can effectively change the package source code at runtime (like 
meta-programming) and resave the source to disk.  Multiple schemas is like 
multiple packages in the same file.

A SQL table is a package-name-qualified global variable that contains a set of 
records.  You name the whole table the same as how you would name an array 
variable in Perl, and you name an individual record same as how you name a 
scalar (or hash) variable in Perl.  You name it after what it contains.

A SQL view is generally the same as a SQL table from a user's perspective.

A SQL field/column is like an object attribute so you name it like such, after 
what the value in that field of a single record is.

For example, if you have a table that contains records about people, one record 
per person, you can name the whole table "people", you name the fields things 
like "person_id", "name", "birth_date", "street_addr", etc, and when you're 
looking at at single record in a row variable you call it "person" or such.

A SQL stored routine (function or procedure) you name like how you name Perl 
named subroutines.  The parameters or variables inside a stored routine you name 
like you do with Perl routines.

A SQL query that isn't explicitly written as a stored routine is the same as a 
Perl anonymous subroutine, like you get when you say "sub { ... }", complete 
with routine parameters (which SQL calls host parameters) and optional result 
values.

I believe a DBIx::Class ResultSet object is like a SQL view but its generally 
implemented on the Perl side; you could possibly name your variables that hold 
such objects like with SQL views.

-- Darren Duncan




More information about the DBIx-Class mailing list