Using tables
How to make, load, chance and delete tables
A MySQL database is constructed from tables. You can make, load, chance and delete tables, normally as many as you like!
If you want to work with tables, you have to load in a database. You can find more explanation for this at the base > Selecting a database.
See all the tables
If you want to see all the tables (without the data in it) you can use the function database.getTables. Here is a example.
let tables = await database.getTables();
console.log(tables); // Get a array with all the tables.To get the amount of tables there are in the database, log the length of
tables.console.log(tables.length); // Get a number of the amount of tables there are.
Making a table
To make a table, use the database.createTable function. This is a example for making a table called example with the columns name, mail and password.
let table = await database.createTable("example", ["name", "mail", "password"]);
// Use the variable "table" for the table functions!Loading a table
If you want to load a table, use the function database.loadTable. This is a example for loading a table called example.
let table = await database.loadTable("example");
// Use the variable "table" for the table functions!Chancing a table
For chancing a table, you have to use the function database.chanceTable. Here you have to give up a action. Look at the different headings for all the actions.
Rename a column
You can rename a column with the action name rename_column. Here is a example where the column nname will be renamed to name in the database example.
await database.chanceTable("example", "rename_column", "nname", "name");
// Done!Deleting a column
You can also delete a column with the action name delete_column. Here is a example where the column hi will be deleted of the database example.
await database.chanceTable("example", "delete_column", "hi");
// Done!Clearing a table
If you want to reset all the data of a table, you can do that with the action clear. Here is a example where the table example will be cleared.
await database.chanceTable("example", "clear");
// Done!Cloning a table
If you want to clone a table (for a backup), you can use the clone action. Here is a example where the table example will be cloned to example2.
await database.chanceTable("example", "clone", "example2");
// Done!Deleting a table
If you want to delete a table, use the function database.deleteTable. Here is a example where the table example will get deleted.
await database.deleteTable("example");
// Done!Last updated
Was this helpful?