2.0.4 • Published 2 years ago

effective_knex v2.0.4

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

effective_knex

License: MIT NPM Downloads Play with docs

Instructions:

npm install effective_knex
const effective_knex =  require('effective_knex')

If utilizing in html...:

<script src="./node_modules/effective_knex/index.js"></script>
<script> 
$(()=> { 
     const output =  effective_knex.method(parameter)
 })
</script>

Purpose

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

User Requirements:

  • Users will be able to be confident in their posts (especially if they have more than one definition for a specific item - e.g., could be "easy" in the UI but the label in the database would be 1)
  • Users will be able to feel confident in their updates
       // example of callback - object 
        "difficulty": function(difficulty) {
          if (difficulty === 1) {
              return "easy"
          } else if (difficulty === 2) {
              return "medium"
          } else if (difficulty === 3) {
              return "hard"
          } else if (difficulty === "hard") {
              return 3
          } else if (difficulty === "medium") {
              return 2
          } else if (difficulty === "easy") {
              return 1
          } else {
              return undefined
          }
      },
  await post(knex, table, object, callbacks) // returns trimmed object
  await update(knex, table, id, object, callbacks = undefined) // returns trimmed object
  await updateOne(knex, table, id, key, value) // returns object
  await tableColValCount(knex, table, col, val) // returns number
  await getObjectCount(knex, table, object) // returns number
  await delById(knex, table, id)
  await delByKeyValue(knex, table, key, value)
  await del(knex, table, id, arrOfOtherTables = undefined)
  await getOneById(knex, table, id)
  await getOneByKeyAndValue(knex, table, key, value)
  await getByKeyValue(knex, table, key, value)
  await getByObject(knex, table, object)
  await getAll(knex, table)
  await getInfo(knex, table, "object")
  await getInfo(knex, table, "array")
  await getTables(knex)
  await getForeignTables(knex, table)
  await postFakeData(knex, table, 20)

Functions

post() ⇒ object

Kind: global function
Date: 2022-03-11
Author: zen-out
Example

let testPost = await post(knex, "hourglass", { start: "2011-02-02" }, callbacks)

update() ⇒ object

Kind: global function
Date: 2022-03-11
Author: zen-out
Example

let testUpdate = await update(knex, "hourglass", testPost.id, { start: "2012-02-02" }, callbacks)

updateOne() ⇒ object

updateOne

Kind: global function
Date: 2022-03-16
Author: zen-out

cleanPostObject() ⇒ 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: global function
Date: 2022-02-16

s={}
Author: zen-out
Example

knexCleanObject.cleanPostObject(knex, "hourglass", object, callbacks )

cleanUpdateObject() ⇒ object

  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: global function
Date: 2022-02-16
Author: zen-out

tableColValCount() ⇒ number

Kind: global function
Date: 2022-03-10
Author: zen-out
Example

let getCount = await tableColValCount(knex, table, col, val)

getObjectCount() ⇒ number

Kind: global function
Date: 2022-03-23
Author: zen-out
Example

await getObjectCount(knex, table, object)

dataExistsAndMatches() ⇒ object

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

Kind: global function
Author: zen-out
Example

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

delByKeyValue()

Kind: global function
Author: github.com/zen-out

deleteFromOtherTables()

Kind: global function
Author: github.com/zen-out
Example

await deleteFromOtherTables(knex, table, id, arrOfOtherTables)

del() ⇒ number

  • If there is a fourth parameter
  • Get foreign id by table_id
  • Delete from other tables

Kind: global function
Date: 2022-03-10
Author: zen-out
Example

del(knex, table, id, arrOfOtherTables = undefined)
let result2 = await del(knex, "hourglass", 54, ["problem"]).then((result) => {
      let check = typeof result === "object"
      return check;
  })

getOneById() ⇒ object

Kind: global function
Date: 2022-03-10
Author: zen-out
Example

// getOne(knex, "hourglass", 11).then((result) => {
       //     console.log(result)
       // })

getOneByKeyAndValue() ⇒ object

Kind: global function
Date: 2022-03-10
Author: zen-out
Example

// getOne(knex, "hourglass", 11).then((result) => {
   //     console.log(result)
   // })

getByKeyValue() ⇒ array

Kind: global function
Date: 2022-03-15
Author: zen-out
Example

let result2 = await getByKeyValue(knex, "user", "id", 4).then((result) => {
        console.log(result)
    })

getByObject()

Kind: global function
Author: github.com/zen-out
Example

await getByObject(knex, "user", {priority: 2})

getAll() ⇒ array

Kind: global function
Date: 2022-03-10
Author: zen-out
Example

// getAll(knex, "hourglass").then((result) => {
    //     console.log(result)
    // })

handleCallbacks() ⇒ any

Kind: global function
Date: 2022-02-16
Author: zen-out
Example

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

getCleanObject() ⇒ 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: global function
Date: 2022-02-16
Author: zen-out

getInfo() ⇒ object

  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: global function
Date: 2022-02-16
Author: zen-out
Example

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

getTables() ⇒ array

Kind: global function
Date: 2022-03-10
Author: zen-out
Example

getTables(knex)

getForeignTables() ⇒ any

Kind: global function
Date: 2022-03-10
Author: zen-out
Example

getForeignTables(knex, table)
// will return ["user"]

getTableBody() ⇒ any

Kind: global function
Date: 2022-03-10
Author: zen-out

makeData(number) ⇒ any

Kind: global function
Date: 2022-03-10
Author: zen-out

ParamType
numberany

postFakeData(number) ⇒ any

Kind: global function
Date: 2022-03-10
Author: zen-out

ParamType
numberany
1.0.19

2 years ago

1.0.18

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.4

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

2.0.1

2 years ago

1.0.23

2 years ago

1.0.27

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago