Skip to content

使用 node demo.js 无法运行事例 #1

@fengdanbailu

Description

@fengdanbailu

1)按例子写,会报错如下:
const {error, result}= await hMysql.table('mytable').where().select().execSql();
^^^^^
SyntaxError: await is only valid in async function
2)去掉 await,返回值是一个 promise;不报错,但没有响应结果
2020-08-03 13:50:00 | SELECT * FROM mytable
undefined
3)如果只是第一句const result= hMysql.table('mytable');console.log(result);
不报错,能返回一个大对象,如下

hMysql {
connection: Pool {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
config: PoolConfig {
acquireTimeout: 1000,
connectionConfig: [ConnectionConfig],
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
},
_acquiringConnections: [],
_allConnections: [],
_freeConnections: [],
_connectionQueue: [],
_closed: false,
[Symbol(kCapture)]: false
},
sqlObj: { table: 'mytable' },
tempObj: {},
config: {
host: 'localhost',
port: 3306,
user: 'root',
password: '‘,
database: 'exercise',
acquireTimeout: 1000,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
isPool: true,
defaultSqlPre: '',
isDebug: true
},
mixed: {
table: [Function: bound table],
alias: [Function: bound alias],
field: [Function: bound field],
where: [Function: bound where],
data: [Function: bound data],
order: [Function: bound order],
limit: [Function: bound limit],
page: [Function: bound page],
join: [Function: bound join],
union: [Function: bound union],
distinct: [Function: bound distinct],
lock: [Function: bound lock],
comment: [Function: bound comment],
group: [Function: bound group],
having: [Function: bound having],
count: [Function: bound count],
max: [Function: bound max],
min: [Function: bound min],
avg: [Function: bound avg],
sum: [Function: bound sum],
select: [Function: bound select],
find: [Function: bound find],
update: [Function: bound update],
insert: [Function: bound insert],
delete: [Function: bound delete],
query: [Function: bound query],
connect: [Function: bound connect],
poolEvent: [Function: bound poolEvent],
execSql: [Function: bound execSql] AsyncFunction,
transaction: [Function: bound transaction] AsyncFunction
},
isMixedWith: [Function (anonymous)],
pageNum: 1,
pageSize: 50
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions