1.2.3 • Published 2 years ago

knex_cleandata v1.2.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

NPM Downloads

Purpose

To be able to quickly render a knex post, and match whatever value that you are trying to post to your database

Directions

See example here - example

  1. Install the package
npm install knex_cleandata
  1. Instantiate it in a javascript file
const {knexCleanData} = require("knex_cleandata")
  1. Pass in object configuration
1. knex database
2. table name
3. callback functions (specific ones that you want)
See example here - [example](https://github.com/lezzles11/knex_cleandata/tree/master/callbackExample.js)
4. object to post 

    let data = await cleanKnexPost.init({ knex: knex, table: "datetime", callbacks: callbacks, object: getObject })
  1. Enjoy!

CleanKnexPost

Kind: global class
Date: 2022-02-16

new CleanKnexPost()

let cleanKnexPost = new CleanKnexPost()

cleanKnexPost.init(options) ⇒ any

init(options)

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamType
optionsany

cleanKnexPost.trimArr(arr) ⇒ any

Trims value of object if it's a string

Kind: instance method of CleanKnexPost
Date: 2022-02-15

ParamType
arrany

cleanKnexPost.trimObj() ⇒ object

this.trimObj(obj) - cleans the object (values)

Kind: instance method of CleanKnexPost
Date: 2022-02-16

cleanKnexPost.handleCallbacks(callbacks, columnName, value) ⇒ any

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamType
callbacksany
columnNameany
valueany

Example

this.handleCallbacks({
    "importance": function(value) {
        if column is importance, then
        return 3
    }
}, "importance", 3)
// returns "high"

cleanKnexPost.finalClean(knex, table, obj) ⇒ any

final step before returning object (removes NaN if supposed to be a number)

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamType
knexany
tableany
objany

cleanKnexPost.cleanPostObject(knex, table, checkObj, callbacks) ⇒ any

  1. Trims object
  2. If it has id, will delete it
  3. Gets table (only matches with values that has table)
  4. Gets keys from that table
  5. Loops through array
  6. If there is a callback passed in and the key matches the column, then it will assign that to the new object
  7. If the column type doesn't match the column value

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamTypeDefault
knexany
tableany
checkObjany
callbacksany{}

cleanKnexPost.getTableInfo(knex, table, type) ⇒ any

  1. Has a dictionary -
  2. Gets knex(table).columnInfo()
  3. if property isn't created
  4. Push it into array called tableColumns
  5. If third parameter is object, will return key and value pairs of column: type. Else, if third parameter is array, will return an array of the key values

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamTypeDefault
knexany
tableany
typeany" object"

Example

this.getTableInfo(knex, "hourglass", "object")
// returns {emails: string... }

cleanKnexPost.dataExistsAndMatches(knex, table, checkObj) ⇒ any

  1. Deletes id from the object, if we are posting
  2. Grabs table columns
  3. Loops through the table column array
  4. If the object has that property and the value is not ""
  5. Append it to newObj
  6. Return newObj

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamType
knexany
tableany
checkObjany

Example

this.dataExistsAndMatches(knex, "hourglass", {
    email: "hello"
})
// output: 
this.dataExistsAndMatches(knex, "hourglass", {
    {
        start: '11/11/2011',
        edit: '2011/11/11',
        end: '2021-12-03'
    }
})
// output  { start: '11/11/2011', edit: '2011/11/11', end: '2021-12-03' }

cleanKnexPost.formatObject(colName, object) ⇒ any

cleanData.formatObject(colName, object) Will format date for us

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamType
colNameany
objectany

cleanKnexPost.formatNumber(colName, number) ⇒ any

formatNumber

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamType
colNameany
numberany

cleanKnexPost.formatString(colName, string, callbacks) ⇒ any

formatString

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamTypeDefault
colNameany
stringany
callbacksany{}

cleanKnexPost.formatBoolean(colName, bool) ⇒ any

formatBoolean

Kind: instance method of CleanKnexPost
Date: 2022-02-16

ParamType
colNameany
boolany
1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago