sunfuze / egg-knex Goto Github PK
View Code? Open in Web Editor NEWknex plugin for egg
License: MIT License
knex plugin for egg
License: MIT License
配置部分:
${app_root}/config/plugin.ts:
import { EggPlugin } from 'egg';
const plugin: EggPlugin = {
knex: {
enable: true,
package: 'egg-knex'
}
};
export default plugin;
${app_root}/config/config.${env}.ts:
import { DefaultConfig } from './config.default';
export default () => {
const config: DefaultConfig = {};
config.knex = {
client: {
dialect: 'mysql',
connection: {
host: '127.0.0.1',
port: '3306',
user: 'root',
password: '111111',
database: 'life'
},
pool: { min: 0, max: 5 },
acquireConnectionTimeout: 30000,
},
app: true,
agent: true,
}
return config;
};
结果:
在Application对象上获取不到knex?
README中的update示例有问题,return回来的是更新的行数,不是数组不需要结构赋值。update传入的row已经为对象,不需要加外层大括号
const row = {
name: 'fengmk2',
otherField: 'other field value',
modifiedAt: app.knex.raw('CURRENT_TIMESTAMP'),
};
// Returns [1] in "mysql", "sqlite", "oracle"; [] in "postgresql" unless the 'returning' parameter is set.
const affectedRows = yield app.knex('posts')
.update(row)
.where(id, 1);
在多数据库实例下,acquireConnectionTimeout如何设置?
如下为配置文件:
// Edit config.default.js
exports.knex = {
default: {
acquireConnectionTimeout: 30000,
},
app: true,
agent: false,
};
这样设置后,acquireConnectionTimeout的时间依旧没有生效,是否为我配置错误?感谢!
Edit ${app_root}/config/config.${env}.js 段落中的
...
// port
port: '3306', 这里的 3306在 ts中的type是number,而不是string
...
需要修改为 port:3306,否则会报类型提示不符合的错误。
是否支持自主传入连接参数动态创建knex
后面的代码基本上和原来的已经不一样了,建议由我来维护
Knex.js提供了.orWhere 或查询,请问egg-knex有这个功能的实现吗?在代码和文档里没有找到。
thx
Hi,
I need dynamic connection with user session or cookie params. Is this possible ?
Thanks.
I am getting error during initialization phase Error: SHOW TABLES - ORA-00900: invalid SQL statement
I did #11 to get it working with the oracledb
driver but seems like did not work. Is there another way to connect oracle ?
TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
现在的日志是在coreLogger
在开发的时候会想输出在console里,
能不能像egg-sequelize一样可以自定义日志输出. 默认也是输出到app.logger. 这样方便调试. 不需要去文件里查看.
谢谢!
opening multiple inactive sessions for a given user in oracle db
看到源码已经修复了低版本 mysql 不支持 explain 语句的BUG,何时才能发布?
/config/knex.js 文件
if (app.config.env === 'local') {
config.debug = config.debug || true;
}
貌似永远不会为 false 😂
2021-05-14 19:00:20,137 ERROR 81953 nodejs.TypeError: knex.client._formatQuery is not a function
at Function.<anonymous> (/Users/colin/work/eggjs_demo/backend/node_modules/egg-knex/lib/knex.js:171:23)
at Function.emit (events.js:315:20)
at Client_MySQL.<anonymous> (/Users/colin/work/eggjs_demo/backend/node_modules/knex/lib/knex-builder/make-knex.js:300:10)
at Client_MySQL.emit (events.js:315:20)
at /Users/colin/work/eggjs_demo/backend/node_modules/knex/lib/execution/runner.js:154:21
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Runner.ensureConnection (/Users/colin/work/eggjs_demo/backend/node_modules/knex/lib/execution/runner.js:272:14)
at async Runner.run (/Users/colin/work/eggjs_demo/backend/node_modules/knex/lib/execution/runner.js:30:19)
at async isReady (/Users/colin/work/eggjs_demo/backend/node_modules/egg-knex/lib/knex.js:128:20)
pid: 81953
hostname: xxxxx
2021-05-14 19:00:20,137 ERROR 81953 [app_worker] start error, exiting with code:1
这个插件可以用于生产环境吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.