-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunthis.js
54 lines (48 loc) · 1.54 KB
/
runthis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// To run as standalone
const mysqlx = require('@mysql/xdevapi');
// Connect to server using a connection URL
var mySession = mysqlx.getSession( {
host: 'localhost', port: 33060,
user: 'root', password: '48450311'} )
.then (session =>{
var myDb = session.getSchema('Project');
// Accessing an existing table
var myTable = myDb.getTable('all_seasons');
// var myResult = myTable.select(['id', 'name', 'dept_name']).
// where('name like :name').
// bind('name', 'L%').execute();
var myResult = myTable.select(['player_name', 'college', 'draft_year']).
where('player_name like :player_name').
bind('player_name', 'L%').execute();
return myResult
})
.then(result => {
// Print result
console.log(result.fetchAll());
});
// as a function called by server
module.exports =
{
buildNamePromise : async function (playerName)
{
const mysqlx = require('@mysql/xdevapi');
var playerName = playerName.who + "%"
// Connect to server using a connection URL
var mySession = mysqlx.getSession( {
host: 'localhost', port: 33060,
user: 'root', password: '48450311'} )
.then (session =>{
var myDb = session.getSchema('Project');
// Accessing an existing table
var myTable = myDb.getTable('all_seasons');
var myResult = myTable.select(['player_name', 'pts', 'ast', 'reb', 'season']).
where('player_name like :player_name').
bind('player_name', playerName).execute();
return myResult
})
.then(result => {
return result.fetchAll();
});
return mySession;
}
}