database-creator-js
v1.0.2
Published
create youre database using code
Downloads
9
Readme
database-creator-js v1.0.2
Installation
npm i --save database-creator-js
Use
With the database-creator-js package you can easily create a database without having to install any tools. You can also refresh your database if you have a lot of testing data that you want to clean. the database drops if you run the script and refreshes the data that you defined in the .js file.
You can run your js file using this code
node yourcode.js
Sample code Using js (Node)
// Insert package you just installed
const { table, database } = require('database-creator-js');
// Create with connection with mysql
// NOT INCLUDED IN PACKAGE!
const connection = mysql.createConnection({
multipleStatements: true, // this is important
host: host,
user: user,
password: password
});
//=====================================
// give package a database connection
//=====================================
database.connect(connection);
//=====================================
// Creates a database
//=====================================
// - package will use the database
database.create('testdb');
//=====================================
// Creates a table
//=====================================
// - You need to define a table name and
// the columns using mysql syntax
table.create('users', {
user_id: 'int NOT NULL',
user_name: 'varchar(20) NOT NULL',
user_age: 'int',
});
//=====================================
// Insert data into table
//=====================================
// - You need to define the table you
// want to insert in and the data
table.insert('users', [
[
1,
'username1',
17
],
[
2,
'username2',
18
],
[
3,
'username3',
23
]
])