-
Notifications
You must be signed in to change notification settings - Fork 65
/
app.js
107 lines (79 loc) · 2.35 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var mysql = require('mysql');
var faker = require('faker');
var connection = mysql.createConnection({
host : 'localhost',
user : 'learnwithcolt',
database : 'join_us'
});
for(var i = 0; i < 500; i++){
console.log("HELLO WORLD!");
}
// Execute file with:
// node filename.js
//SELECTING DATA
// var q = 'SELECT COUNT(*) AS total FROM users ';
// connection.query(q, function (error, results, fields) {
// if (error) throw error;
// console.log(results[0].total);
// });
// INSERTING DATA
/*var q = 'INSERT INTO users (email) VALUES ("rusty_the_dog@gmail.com")';*/
// connection.query(q, function (error, results, fields) {
// if (error) throw error;
// console.log(results);
// });
// INSERTING DATA TAKE 2
// var person = {
// email: faker.internet.email(),
// created_at: faker.date.past()
// };
// var end_result = connection.query('INSERT INTO users SET ?', person, function(err, result) {
// if (err) throw err;
// console.log(result);
// });
// connection.end();
// Mon Apr 24 2017 17:10:07 GMT+0000 (UTC)
// "yyyy-mm-dd hh:mm:ss"
// console.log(faker.date.past());
// INSERTING LOTS OF DATA!!!!=============================
var data = [];
for(var i = 0; i < 500; i++){
data.push([
faker.internet.email(),
faker.date.past()
]);
}
// console.log(data);
// var q = 'INSERT INTO users (email, created_at) VALUES ?';
// connection.query(q, [data], function(err, result) {
// console.log(err);
// console.log(result);
// });
// connection.end();
// Find Faker Docs Here: https://github.com/marak/Faker.js/
// Install Faker via command line:
// npm install faker
// Require it inside of a JS file:
var faker = require('faker');
// USE IT!
// Print a random email
console.log(faker.internet.email());
// Print a random past date
console.log(faker.date.past());
// Print a random past date
console.log(faker.address.city());
// We can define a new function
function generateAddress(){
console.log(faker.address.streetAddress());
console.log(faker.address.city());
console.log(faker.address.state());
}
// And then execute that function:
generateAddress();
var q = 'SELECT CURTIME() as time, CURDATE() as date, NOW() as now';
connection.query(q, function (error, results, fields) {
if (error) throw error;
console.log(results[0].time);
console.log(results[0].date);
console.log(results[0].now);
});