项目作者: markwylde

项目描述 :
Allows you to use Knex inside a Cordova app.
高级语言: JavaScript
项目地址: git://github.com/markwylde/knex-cordova-sqlite.git
创建时间: 2020-06-10T10:47:56Z
项目社区:https://github.com/markwylde/knex-cordova-sqlite

开源协议:MIT License

下载


knex-cordova-sqlite

Allows you to use Knex inside a Cordova app.

Prerequisites

This library does not actually provide any bindings to sqlite, but instead connects the cordova-sqlite-storage provided API to Knex.

Therefore, you need to add the cordova-sqlite-storage plugin to your app.

Installation

  1. npm install --save knex-cordova-sqlite

Example Usage

  1. const knex = require('knex')({
  2. client: require('knex-cordova-sqlite'),
  3. connection: {
  4. filename: 'todos-' + Date.now() + '.db'
  5. }
  6. });
  7. async function init () {
  8. await knex.schema.createTable('todos', table => {
  9. table.increments('id');
  10. table.string('title');
  11. })
  12. }
  13. function addTodo (todo) {
  14. return knex('todos').insert(todo)
  15. }
  16. function getTodos () {
  17. return knex('todos').select('*')
  18. }
  19. module.exports = {
  20. init,
  21. addTodo,
  22. getTodos
  23. }