mysql_basic v1.0.0
INTRODUCTION
This is a package for fast startup with MySQL database. The package provides a easy connect to MySQL database and some basic and simple CRUD command.
SETUP
There is a file called "dbconfig.js". Edit the fields in it to provide your Database url(endpoint url), database superuser ID, database superuser password. The name field is now being suspended in this version, in other words you can ignore it.
BASIC CRUD
To create a new record in a table: createRecord(db, tbl, cols, vals);
db: STRING, the name of your database
tbl: STRING, the name of your table
cols: ARRAY, the columns that will contain data
vals: ARRAY, the values that will be stored in the defined field.
REMARKS: cols and vals must be an array with same array's length, or else, error.
Example Usage: createRecord("my_database","my_table","ID","col1","col2","col4","ID123456","val1",num2,boolean4);
To retrieve a list of records in a table: listRecord(db, tbl, cols);
db: STRING, the name of your database
tbl: STRING, the name of your table
cols: ARRAY, the columns that will return in the query
REMARKS: cols must be an array, even returning one field, use "col1"; or returning all fields, use "*"
Example Usage: listRecord("my_database","my_table","*");
To retrieve a list of records with a searching value based on a columns: listSearchedRecords(db, tbl, cols, searchKey, searchVal);
db: STRING, the name of your database
tbl: STRING, the name of your table
cols: ARRAY, the columns that will return in the query
searchKey: STRING, the column name of the searching value.
searchVal: STRING, the value to be searched in the specifc column
REMARKS: cols must be an array, even returning one field, use "col1"; or returning all fields, use "*". the searchKey and searchVal must be provided, searchVal can be one fragment of the actual value.
Example Usage: listSearchedRecords("my_database","my_table","col1","col2","col3","col2","val2");
To update a record with ID: updateRecordWithID(db, tbl, cols, vals, id);
db: STRING, the name of your database
tbl: STRING, the name of your table
cols: ARRAY, the columns that will contain data
vals: ARRAY, the values that will be stored in the defined field.
id: STRING, the column id
in the table, unique id.
REMARKS: cols and vals must be an array with same array's length, or else, error. The id
field must be available in the table for working.
Example Usage: updateRecordWithID("my_database","my_table","col1","col2","col3","val1",num2,float3,"777");
To delete a record in database with ID: deleteRowWithID(db,tbl,id);
db: STRING, the name of your database
tbl: STRING, the name of your table
id: STRING, the column id
in the table, unique id.
REMARKS: The id
field must be available in the table for working.
Example Usage: deleteRowWithID("my_database","my_table","12");
7 years ago