2017-10-31 23:09:36 -04:00
|
|
|
const DatabaseRecord = Class( 'DatabaseRecord',
|
2015-05-15 01:14:40 -04:00
|
|
|
{
|
|
|
|
/* implicitly private */
|
|
|
|
_connection: null,
|
|
|
|
|
|
|
|
|
2017-10-31 23:09:36 -04:00
|
|
|
constructor( host, user, pass )
|
2015-05-15 01:14:40 -04:00
|
|
|
{
|
|
|
|
this._connection = this._connect( host, user, pass );
|
|
|
|
},
|
|
|
|
|
|
|
|
/* implicitly private */
|
2017-10-31 23:09:36 -04:00
|
|
|
_connect( host, user, pass )
|
2015-05-15 01:14:40 -04:00
|
|
|
{
|
|
|
|
// (do connection stuff)
|
|
|
|
return { host: host };
|
|
|
|
},
|
|
|
|
|
2017-10-31 23:09:36 -04:00
|
|
|
'protected query'( query )
|
2015-05-15 01:14:40 -04:00
|
|
|
{
|
|
|
|
// perform query on this._connection, rather than exposing
|
|
|
|
// this._connection to subtypes
|
|
|
|
},
|
|
|
|
|
2017-10-31 23:09:36 -04:00
|
|
|
'protected escapeString'( field )
|
2015-05-15 01:14:40 -04:00
|
|
|
{
|
|
|
|
return field.replace( "'", "\\'" );
|
|
|
|
},
|
|
|
|
|
|
|
|
/* public by default */
|
2017-10-31 23:09:36 -04:00
|
|
|
getName( id )
|
2015-05-15 01:14:40 -04:00
|
|
|
{
|
|
|
|
return this._query(
|
|
|
|
"SELECT name FROM users WHERE id = '" +
|
|
|
|
this._escapeString( id ) + "' LIMIT 1"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
} );
|