I am having a little trouble with retrieving the data from a table using knex select.
I would like to do something like this
function getUserData(userId){
let user = knex.select('xp','money','rolls','twenty').from('users').where('user_id', userId);
return user;
}
user = getUserData(userId);
user.xp; // do something with this value
but this outputs the following (if i console.log it), but not the requested info from the Select query, unless i am just not sure how to retrieve it:
Builder {
client:
Client_MySQL {
config: { client: 'mysql', connection: [Object] },
connectionSettings:
{ host: '127.0.0.1',
user: 'XXXXXXXXXX',
password: 'XXXXXXXXXX',
database: 'XXXXXXXXXX' },
driver:
{ createConnection: [Function: createConnection],
createPool: [Function: createPool],
createPoolCluster: [Function: createPoolCluster],
createQuery: [Function: createQuery],
escape: [Function: escape],
escapeId: [Function: escapeId],
format: [Function: format],
raw: [Function: raw] },
pool:
Pool {
creator: [Function: create],
destroyer: [Function: destroy],
validate: [Function: validate],
log: [Function],
acquireTimeoutMillis: 60000,
createTimeoutMillis: 30000,
idleTimeoutMillis: 30000,
reapIntervalMillis: 1000,
createRetryIntervalMillis: 200,
propagateCreateError: true,
min: 2,
max: 10,
used: [],
free: [],
pendingCreates: [],
pendingAcquires: [],
destroyed: false,
interval: null },
valueForUndefined:
Raw {
client: [Circular],
sql: 'DEFAULT',
bindings: undefined,
_wrappedBefore: undefined,
_wrappedAfter: undefined,
_debug: undefined },
_events:
{ start: [Function],
query: [Function],
'query-error': [Function],
'query-response': [Function] },
_eventsCount: 4,
makeKnex: [Function: makeKnex] },
and: [Circular],
_single: { table: 'users', only: false },
_statements:
[ { grouping: 'columns', value: [Array] },
{ grouping: 'where',
type: 'whereBasic',
column: 'user_id',
operator: '=',
value: '341007826375802900',
not: false,
bool: 'and' } ],
_method: 'select',
_debug: undefined,
_joinFlag: 'inner',
_boolFlag: 'and',
_notFlag: false }
I'll write some more words here, as it requires me to do so, since it is mostly code. I hope this will be enough words.