Giter VIP home page Giter VIP logo

feathers-knex's Introduction

feathers-knex

Greenkeeper badge

Build Status Code Climate Test Coverage Dependency Status Download Status Slack Status

A Knex.js service adapter for FeathersJS

Installation

npm install feathers-knex --save

Documentation

Please refer to the Feathers database adapter documentation for more details or directly at:

  • KnexJS - The detailed documentation for this adapter
  • Extending - How to extend a database adapter
  • Pagination - How to use pagination
  • Querying and Sorting - The common adapter querying mechanism and sorting for the database adapter

Complete Example

Here's a complete example of a Feathers server with a todos SQLite service. We are using the Knex schema builder

import feathers from 'feathers';
import rest from 'feathers-rest';
import bodyParser from 'body-parser';
import knexService from 'feathers-knex';

// Initialize knex database adapter
const knex = require('knex')({
  client: 'sqlite3',
  connection: {
    filename: './db.sqlite'
  }
});

// Create Knex Feathers service with a default page size of 2 items
// and a maximum size of 4
var todos = knexService({
  Model: knex,
  name: 'todos',
  paginate: {
    default: 2,
    max: 4
  }
});

// Create a feathers instance.
const app = feathers()
  // Enable REST services
  .configure(rest())
  // Turn on JSON parser for REST services
  .use(bodyParser.json())
  // Turn on URL-encoded parser for REST services
  .use(bodyParser.urlencoded({ extended: true }));

// Initialize the database table with a schema
// then mount the service and start the app
todos
  .init({}, function(table) {

    //define your schema
    console.log(`created ${table._tableName} table`);
    table.increments('id');
    table.string('text');
    table.boolean('complete');

  }).then(() => {

    app.use('/todos', todos);

    app.use(function(error, req, res, next){
      res.json(error);
    });

    // Start the server.
    const port = 8080;
    app.listen(port, function() {
      console.log(`Feathers server listening on port ${port}`);
    });

  });

You can run this example by using node server and going to localhost:8080/todos. You should see an empty array. That's because you don't have any Todos yet but you now have full CRUD for your new todos service!

License

Copyright (c) 2016

Licensed under the MIT license.

feathers-knex's People

Contributors

ahdinosaur avatar arlair avatar corymsmith avatar daffl avatar ekryski avatar greenkeeper[bot] avatar greenkeeperio-bot avatar jayalfredprufrock avatar kc-dot-io avatar lvivier avatar marshallswain avatar mcchrish avatar nilsboy avatar pnakibar avatar runningskull avatar t2t2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.