Skip to content

Commit

Permalink
init code
Browse files Browse the repository at this point in the history
  • Loading branch information
phu.phan committed Apr 9, 2024
1 parent 029707d commit df059e5
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
32 changes: 32 additions & 0 deletions faker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const {faker} = require("@faker-js/faker")

function createRanbdomUser(){
return {
id:faker.string.uuid(),
manager_id: faker.string.uuid(),
azure_id: faker.string.uuid(),
slack_id: faker.string.uuid(),
role: "ADMIN",
type:"REMOTE",
name: faker.internet.userName(),
address: faker.location.streetAddress(),
group:"MEDIBA",
company_phone_number: "81-3-6825-0189",
department: "IT",
position: "STAFF",
area_code: "76",
office_name:"Vietlink"
}
}

function createUser() {
const user = faker.helpers.multiple(createRanbdomUser, {
count: 1000,
});
return user;

}

module.exports = {
createUser,
}
1 change: 1 addition & 0 deletions insert_users.sql

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions intervalsend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export enum Emergency {
TSUNAMI = "TSUNAMIS",
EARTHQUAKES = "EARTHQUAKES",
}

function CallbackInterval(type, time, listAlert) {
// check is reponse --> update resposne
// clear to array user not response
// next send interval
}
11 changes: 11 additions & 0 deletions mysql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'phankieuphu',
password : 'phankieuphu123',
database : 'nestdemo',
port:3306
});


module.exports = connection;
110 changes: 110 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"@faker-js/faker": "^8.4.1",
"mysql": "^2.18.1"
}
}
32 changes: 32 additions & 0 deletions renderfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require('fs');
const {createUser} = require('./faker')
// Function to generate SQL insert statements for an array of users
console.time('generateInsertStatements')
function generateInsertStatements(users) {
let sqlStatements = '';
sqlStatements += `INSERT INTO users (id, manager_id, azure_id, slack_id, role, type, name, address, \`group\`, company_phone_number, department, position, area_code, office_name) VALUES `;
// Iterate over each user and generate insert statement
users.forEach(user => {
const values = Object.values(user).map(value => {
// If value is a string, escape single quotes
if (typeof value === 'string') {
return "'" + value.replace(/'/g, "''") + "'";
}
return value;
}).join(', ');
sqlStatements += `(${values}) , `

});

return sqlStatements + ';';
}
console.timeEnd("generateInsertStatements");
// Function to write SQL insert statements to a file
function writeInsertStatementsToFile(insertStatements, fileName) {
fs.writeFileSync(fileName, insertStatements);
console.log(`SQL insert statements have been written to ${fileName}`);
}

// Example usage
const insertStatements = generateInsertStatements(createUser()); // Generate SQL insert statements
writeInsertStatementsToFile(insertStatements, 'insert_users.sql'); // Write insert statement

0 comments on commit df059e5

Please sign in to comment.