Socket
Socket
Sign inDemoInstall

feathers-knex-modeler

Package Overview
Dependencies
9
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.1 to 1.4.2

.vscode/settings.json

16

package.json
{
"name": "feathers-knex-modeler",
"version": "1.4.1",
"version": "1.4.2",
"description": "This package allows you to easily extend a table while you are developing it without requiring you to drop tables.",

@@ -17,13 +17,13 @@ "main": "src/index.js",

"debug": "^4.1.1",
"delay": "^4.1.0",
"lodash": "^4.17.11",
"p-queue": "^3.0.0",
"p-wait-for": "^2.0.1"
"delay": "^4.3.0",
"lodash": "^4.17.15",
"p-queue": "^6.2.1",
"p-wait-for": "^3.1.0"
},
"devDependencies": {
"chai": "^4.2.0",
"knex": "^0.16.3",
"mocha": "^5.2.0",
"pg": "^7.8.0"
"knex": "^0.20.7",
"mocha": "^7.0.0",
"pg": "^7.17.0"
}
}

@@ -7,3 +7,3 @@ /* eslint-disable no-console */

const debug = require('debug')
const PQueue = require('p-queue')
const { default: PQueue } = require('p-queue')
class Model extends EventEmitter {

@@ -20,3 +20,3 @@ constructor (options) {

Object.defineProperty(self._, 'default', { enumerable: false, value: options.default })
let tableName = _.get(self, '_.name')
const tableName = _.get(self, '_.name')
self.debug = debug(`feathers-knex-modeler:${tableName}`)

@@ -29,18 +29,23 @@ self.debug(`Finished construction of model for table: ${tableName}`)

}
get db () {
return this._.db
}
get default () {
return this._.default
}
get depends () {
return this._.depends
}
get name () {
return this._.name
}
async init () {
const self = this
const db = self.db
let tableName = self.name
const tableName = self.name
self.debug(`Starting initialization of model for table: ${tableName}`)

@@ -70,2 +75,3 @@ let encounteredErrors = false

}
emit (...args) {

@@ -78,2 +84,3 @@ if (args.length === 1) {

}
async hasColumn (tableName, columnName, retries = 0) {

@@ -101,2 +108,3 @@ const self = this

}
async waitForColumn (tableName, columnName) {

@@ -106,15 +114,13 @@ const self = this

}
async dropKey (tableName, columnName) {
const self = this
let done = false
let columnInfo
console.log(tableName)
columnInfo = await self.db(tableName).columnInfo(columnName)
console.log(columnInfo)
const done = false
const columnInfo = await self.db(tableName).columnInfo(columnName)
await pWaitFor(() => {
return done
})
console.log(columnInfo)
return columnInfo
}
async alterColumn (column, option, allOptions) {

@@ -126,4 +132,4 @@ const self = this

self.debug(option)
let hasOnDelete = _.defaultTo(_.find(allOptions, { type: 'onDelete' }), false)
let hasOnUpdate = _.defaultTo(_.find(allOptions, { type: 'onUpdated' }), false)
const hasOnDelete = _.defaultTo(_.find(allOptions, { type: 'onDelete' }), false)
const hasOnUpdate = _.defaultTo(_.find(allOptions, { type: 'onUpdated' }), false)
self.debug(`Column: ${column.name}, has onDelete defined: ${hasOnDelete !== false}`)

@@ -134,5 +140,5 @@ self.debug(`Column: ${column.name}, has onUpdated defined: ${hasOnUpdate !== false}`)

let alterCommand
let typeOfColumn = option.type
let argument = option.argument
let columnToAlter = self.tableColumnUtilityMethod(table, column)
const typeOfColumn = option.type
const argument = option.argument
const columnToAlter = self.tableColumnUtilityMethod(table, column)

@@ -191,3 +197,3 @@ switch (typeOfColumn) {

self.debug(err)
let alreadyExists = (err.message.indexOf('already exists') !== -1)
const alreadyExists = (err.message.indexOf('already exists') !== -1)
if (alreadyExists === false) {

@@ -203,11 +209,12 @@ errored = err

}
async createColumn (column) {
const self = this
column.options = column.options || []
let waitingOnQueue = new PQueue({ concurrency: 1 })
const waitingOnQueue = new PQueue({ concurrency: 1 })
_.forEach(column.options, (columnOption) => {
if (columnOption.type === 'references') {
let splitArray = columnOption.argument.split('.')
let dependTable = splitArray[0]
let dependColumn = splitArray[1]
const splitArray = columnOption.argument.split('.')
const dependTable = splitArray[0]
const dependColumn = splitArray[1]
waitingOnQueue.add(() => self.waitForTableColumn(dependTable, dependColumn))

@@ -217,8 +224,9 @@ }

await waitingOnQueue.onIdle()
self.debug(`All dependencies found`)
let hasColumn = await self.hasColumn(self.name, column.name)
self.debug(`Altering table`)
self.debug('All dependencies found')
const hasColumn = await self.hasColumn(self.name, column.name)
self.debug('Altering table')
await self.alterTable(hasColumn, column)
self.debug(`Finished altering table`)
self.debug('Finished altering table')
}
tableColumnUtilityMethod (table, column) {

@@ -237,6 +245,7 @@ let columnToReturn

}
async alterTable (hasColumn, column) {
const self = this
const db = self.db
let alterations = []
const alterations = []
await db.schema.alterTable(self.name, (table) => {

@@ -257,2 +266,3 @@ if (hasColumn === false) {

}
async createColumns () {

@@ -262,5 +272,5 @@ try {

const columns = self.columns
let columnsBeingCreated = []
const columnsBeingCreated = []
for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
let column = columns[columnIndex]
const column = columns[columnIndex]
self.debug(`Creating Column: ${column.name}`)

@@ -275,2 +285,3 @@ columnsBeingCreated.push(self.createColumn(column, columns))

}
async createTable (tableName) {

@@ -281,3 +292,3 @@ const self = this

self.debug(`Creating table: ${tableName}`)
let hasTable = await self.hasTable(tableName)
const hasTable = await self.hasTable(tableName)
if (hasTable === false) {

@@ -291,2 +302,3 @@ return db.schema.createTable(self.name, function () {

}
async waitForTable (tableName) {

@@ -297,7 +309,8 @@ const self = this

}
async waitForTables () {
const self = this
let tablesBeingCreated = []
const tablesBeingCreated = []
for (let dependsIndex = 0; dependsIndex < self.depends.length; dependsIndex++) {
let dependedOnTableName = self.depends[dependsIndex]
const dependedOnTableName = self.depends[dependsIndex]
tablesBeingCreated.push(self.waitForTable(dependedOnTableName))

@@ -308,2 +321,3 @@ }

}
async waitForTableColumn (tableName, columnName) {

@@ -317,13 +331,15 @@ const self = this

}
async hasTable (tableName) {
const self = this
const db = self.db
let exists = await db.schema.hasTable(tableName)
const exists = await db.schema.hasTable(tableName)
return exists
}
async hasTables () {
const self = this
let dependedOnTables = []
const dependedOnTables = []
for (let dependsIndex = 0; dependsIndex < self.depends.length; dependsIndex++) {
let dependedOnTableName = self.depends[dependsIndex]
const dependedOnTableName = self.depends[dependsIndex]
dependedOnTables.push(self.hasTable(dependedOnTableName))

@@ -330,0 +346,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc