[英]Knex.js on create-react-native-app
I am trying to use Knex.js ( http://knexjs.org/
) to manage the SQLite database that comes with Expo ( https://docs.expo.io/versions/latest/sdk/sqlite.html
.) When I import knex, it crashes because of some missing node.js packages like "events", "streams", "assert", etc. 我正在尝试使用Knex.js(
http://knexjs.org/
)管理Expo( https://docs.expo.io/versions/latest/sdk/sqlite.html
)附带的SQLite数据库。我导入knex,它由于缺少“事件”,“流”,“断言”等一些node.js包而崩溃。
So clearly it seems to think it is in a node.js environment which isn't what create-react-native-app provides by default. 所以很显然,它似乎认为它是在node.js环境中,而不是默认情况下create-react-native-app提供的。
I only need it to generate SQL query strings for a better development interface (compared to string manipulation and concatenation). 我只需要它来生成SQL查询字符串,以获得更好的开发接口(与字符串操作和串联相比)。
Has anyone got knex.js to work on create-react-native-app? 有没有人让knex.js可以使用create-react-native-app?
you won't be able to use it at all, so its not a matter of 'has anyone' done it yet. 您将根本无法使用它,因此这不是“是否有人”完成了。 You can't get a full node API environment in a ReactNative app.
您无法在ReactNative应用程序中获得完整的节点API环境。
You could pack query builder parts of knex ( .toNative()
comes in knex 0.14) to your react app and then create queries like: 您可以将knex的查询构建器部分(
.toNative()
0.14中的.toNative()
附带)打包到您的react应用程序中,然后创建如下查询:
knex('MyTable').where('id', 1).toSQL().toNative()
// Will output
// {
// sql: 'select * from `MyTable` where `id` = ?',
// bindings: [1]
// }
Knex documentation page is also using that way to render built queries in http://knexjs.org/ Knex文档页面也使用这种方式在http://knexjs.org/中呈现内置查询。
Probably you need to use webpack or something like that to build standalone version of knex. 可能您需要使用webpack或类似的东西来构建独立版本的knex。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.