effective_knex v2.0.4
effective_knex
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
- Trims object
- If it has id, will delete it
- Gets table (only matches with values that has table)
- Gets keys from that table
- Loops through array
- If there is a callback passed in and the key matches the column, then it will assign that to the new object
- 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
- Trims object
- If it has id, will delete it
- Gets table (only matches with values that has table)
- Gets keys from that table
- Loops through array
- If there is a callback passed in and the key matches the column, then it will assign that to the new object
- 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
- Deletes id from the object, if we are posting
- Grabs table columns 3.Loops through the table column array
- If the object has that property and the value is not ""
- Append it to newObj
- 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
- Trims object
- If it has id, will delete it
- Gets table (only matches with values that has table)
- Gets keys from that table
- Loops through array
- If there is a callback passed in and the key matches the column, then it will assign that to the new object
- If the column type doesn't match the column value
Kind: global function
Date: 2022-02-16
Author: zen-out
getInfo() ⇒ object
- Has a dictionary -
- Gets knex(table).columnInfo()
- if property isn't created
- Push it into array called tableColumns
- 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
Param | Type |
---|---|
number | any |
postFakeData(number) ⇒ any
Kind: global function
Date: 2022-03-10
Author: zen-out
Param | Type |
---|---|
number | any |
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago