I have an AngularJs app which connects to a database using php PDO APIs.
This is the schematic data flow:
DB:
CREATE TABLE person (
...
first_name,
...
);
php API:
$stmt = $this->db->prepare("SELECT * FROM person");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);
...
'first_name' => 'Alice',
...
angular service:
getPerson: function (id) {
return $http({
method: 'GET',
url: apiUri + 'get' + '/' + id,
}).then(handleSuccess, handleError);
},
angular controller:
Person.getPerson(id).then(function(person) {
var name = person.first_name; // this throws a jslint warning
});
The problem is SQL recommended naming standard is underscore_case, while Angular's is camelCase...
I would not like to disable jslint, which is very useful, in other respects...
I know I could avoid warnings even with
{
"camelcase": false
}
in .jshintrc, but I'd prefer not to disable camelcase check globally...
Currently I avoid jslint warnings with "jslint comments", this way:
/* jshint camelcase: false */
var name = person.first_name;
/* jshint camelcase: true */
but my code is going to contain more jslint comments than code... Quite unreadable...
How do you (or would you) solve this issue?
As underscore_case is not mandatory with SQL and camelCase is mandatory with Angular it is sesible to use names suitable for both environments. In this case camelCase is acceptable with both.
In 40+ years programming I never thought underscore_case was useful. I have always preferred camelCase. Rename first_name to firstName it not only looks better but it will solve the problem.
EDIT
Column names in Standard SQL can consist of letters, underscores, and digits starting with a letter. SQL allows you to use spaces, reserved words, and special characters in a name if you enclose them in double quotation marks.
Identifiers not only have to be meaningful they have to be unique. So in choosing a naming convention the environment in which the operate has to be taken into consideration
Windows
SQL is case insesitive ie, NAME == name == Name == NaMe
Unix
SQL is case sesitive ie, NAME != name != Name != NaMe
Michael Lato recomends PascalCase for MS Server, Oracle uses UPPER with underscores. MySQL recomends lower with underscores BUT this is not mandatory See
NOTE
On Windows, InnoDB always stores database and table names internally in lowercase