2017-10-31 23:09:36 -04:00
|
|
|
const DatabaseRecord = Class( 'DatabaseRecord',
|
2012-05-05 14:09:27 -04:00
|
|
|
{
|
|
|
|
'private _connection': null,
|
|
|
|
|
|
|
|
|
2017-10-31 23:09:36 -04:00
|
|
|
constructor( host, user, pass )
|
2012-05-05 14:09:27 -04:00
|
|
|
{
|
|
|
|
this._connection = this._connect( host, user, pass );
|
|
|
|
},
|
|
|
|
|
2017-10-31 23:09:36 -04:00
|
|
|
'private _connect'( host, user, pass )
|
2012-05-05 14:09:27 -04:00
|
|
|
{
|
|
|
|
// (do connection stuff)
|
|
|
|
return { host: host };
|
|
|
|
},
|
|
|
|
|
2017-10-31 23:09:36 -04:00
|
|
|
'protected query'( query )
|
2012-05-05 14:09:27 -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 )
|
2012-05-05 14:09:27 -04:00
|
|
|
{
|
|
|
|
return field.replace( "'", "\\'" );
|
|
|
|
},
|
|
|
|
|
2017-10-31 23:09:36 -04:00
|
|
|
'public getName'( id )
|
2012-05-05 14:09:27 -04:00
|
|
|
{
|
|
|
|
return this._query(
|
|
|
|
"SELECT name FROM users WHERE id = '" +
|
|
|
|
this._escapeString( id ) + "' LIMIT 1"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
} );
|