Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
npm i yamaform --save
A usage example can be found at https://github.com/ricardo93borges/yamaform-example
Instantiate
var Yamaform = require('yamaform')
let databaseConfig = {
host : 'localhost',
user : 'username',
password : 'password',
database : 'database'
}
const yamaform = new Yamaform(databaseConfig, 'database.json')
//Generate tables using "database.json" file
yamaform.generateTables()
JSON file example:
{
"person": {
"name": "varchar(45)",
"age": "integer",
"hasMany": "dog",
"hasOne":"address"
},
"dog": {
"name": "varchar(45)",
"age": "integer",
"hasMany": "person"
},
"address": {
"name": "varchar(45)"
}
}
Relationships
You can specify many to one relationships with hasOne keyword and many to many relationships with keyword hasMany, on the example above, person has one address, so a foreign key called address_id will be created on person table.
Also a person has many dogs and a dog has many persons, so a associative table called person_dog will be created with the foreign keys person_id and dog_id.
If in json file the dog object didn't have a hasMany keyword, a foreign key called person_id would be created in dog table.
In many to many relationships both tables must have a name column.
Every table created will have a column called id that will be a primary key auto incremented
If a table has more then one many to one relationship use hasOne: [table1,table2]
Generate form
let props = {
"method":'put',
"id":1, //Used when method is put
"action":'/',
'formClass':'', //Optional
'labelClass':'', //Optional
'inputClass':'', //Optional
'inputWrapperClass':'', //Optional
'buttonClass':'', //Optional
'buttonText':'', //Optional
}
const getForm = async () => {
let form = await yamaform.generateForm('person', props)
console.log(form)
}
getForm()
generateForm method expects a database table name and an object of properties that will be used in the form element
Fetch data and generate a HTML table
let props = {
"tableClass":'', // Optional
'viewUrl':'/your/url', // Optional, url to view record, will become /your/url/(record id)
'deleteUrl':'/your/url', // Optional, url to delete record, will become /your/url/(record id)
'tableClass':'', // Optional
'viewText':'', // Optional, text for link to view, default: view
'deleteText':'' // Optional, text for link to delete, default: delete
}
const fetch = async () => {
let table = await yamaform.fetch('person', props)
console.log(table)
}
fetch()
fetch method expects a database table name and an object of properties that will be used in the table element
Insert data in database
let data = {
"tableName":[
{"columnName":"value", "columnName":"value"},
{"columnName":"value", "columnName":"value"}
],
"otherTableName":[
{"columnName":"value", "columnName":"value"},
{"columnName":"value", "columnName":"value"}
]
}
const insert = async () => {
let result = await yamaform.insert(data)
console.log(result)
}
insert()
insert method expects a json object with table name and data to be inserted into database, returns an array of IDs of the inserted rows
Update data in database
let data = {
"tableName":[
{"id":"value", "columnName":"value"},
{"id":"value", "columnName":"value"}
],
"otherTableName":[
{"id":"value", "columnName":"value"},
{"id":"value", "columnName":"value"}
]
}
const update = async () => {
let result = await yamaform.update(data)
console.log(result)
}
update()
update method expects a json object with table name and data (must contain the id of the record which will be update) to be inserted into database, returns an array of IDs of the affected rows
Delete from database
let data = {
"tableName":[
{'where':'id = 34'}
],
"otherTableName":[
{'where':'name = "john doe" '}
]
}
const remove = async () => {
let result = await yamaform.remove(data)
console.log(result)
}
remove()
update method expects a json object with table name and a WHERE clause to specify a condition to delete records, returns an array of IDs of the affected rows
FAQs
Generate form and database tables from a json file
The npm package yamaform receives a total of 2 weekly downloads. As such, yamaform popularity was classified as not popular.
We found that yamaform demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.