npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

feathers-knex-modeler

v1.5.1

Published

This package allows you to easily extend a table while you are developing it without requiring you to drop tables.

Downloads

32

Readme

Feathers Knex modeler

This package allows you to easily extend a table while you are developing it without requiring you to drop tables.

Usage

Within Feathers

The below contain the contents of two files the model file and the service file.


// test.model.js - A KnexJS
//
// See http://knexjs.org/
// for more of what you can do here.
module.exports = function (app) {
  const tableName = 'users'
  const db = app.get('knexClient')
  const Modeler = require('feathers-knex-modeler')
  const modeler = new Modeler({
    name: tableName,
    depends: ['organizations'],
    columns:    [
    { name: 'id', type: 'increments' },
    { name:'organization_id',type:'integer',options:[{ type: 'references', argument: 'organizations.id' }]} ,
    { name: 'value', type: 'integer', options: [{ type: 'notNullable' }] },
    { name: 'name', type: 'text', options: [{ type: 'notNullable' }] },
    { name: 'schema_type', type: 'text', options: [{ type: 'notNullable' }] },
    { name: 'status', type: 'text', options: [{ type: 'notNullable' }] },
    { name: 'shared', type: 'bool', options: [{ type: 'notNullable' }] }
  ],
    db
  })
  modeler.init()
  return db
}

// test.service.js - A KnexJS
//
// Initializes the `fields` service on path `/test`
const createService = require('feathers-knex')
const createModel = require('../../models/test.model.js')
const hooks = require('./test.hooks')

module.exports = function (app) {
  const Model = createModel(app)
  const paginate = app.get('paginate')

  const options = {
    name: 'fields',
    Model,
    paginate
  }

  // Initialize our service with any options it requires
  app.use('/fields', createService(options))

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('fields')

  service.hooks(hooks)
}

Standalone

The below contain the contents of two files the model file and the service file.

'use strict'
const knex = require('knex')
const Modeler = require('feathers-knex-modeler')

const db = knex({
  client: 'pg',
  connection: {
    host: '127.0.0.1',
    database: 'myapp_test'
  }
})
const testModel = new Modeler({
  name: 'test',
  depends: [],
  columns: [
    { name: 'id', type: 'increments' },
    { name: 'name', type: 'text', options: [{ type: 'notNullable' }] },
    { name: 'schema_type', type: 'text', options: [{ type: 'notNullable' }] },
    { name: 'status', type: 'text', options: [{ type: 'notNullable' }] },
    { name: 'shared', type: 'bool', options: [{ type: 'notNullable' }] }
  ],
  db
})

testModel.init()