1、生成doc
file/generate_doc.js
- /**
- *
- * @description 拼接mysql字段的值,从中随机取值后,生成doc文件
- */
- const fs = require('fs')
- const mysql_config = require('../config/mysql_config')
- const {connect, read} = require('../mysql/mysql');
-
- (async () => {
- const Mock = require('mockjs')
- let Random = Mock.Random
- let c = await connect(mysql_config.options)
- for (let j = 0; j < 1000; j++) {
- let start = j * 1000
- let end = (j + 1) * 1000
- let sql = `select * from test_data limit ${start},${end}`
- let arr = await read(c, sql)
- let name = Random.csentence(5, 15).replaceAll('。', '')
- for (let i in arr) {
- if (arr.hasOwnProperty(i)) {
- if (parseInt(i) / 100 % 1 === 0 && parseInt(i) !== 0) {
- break
- } else {
- fs.writeFile(`${name}.doc`, JSON.stringify(arr[i]), {flag: 'a', encoding: 'utf8'}, err => {
- if (err) throw err;
- console.log('The file has been saved!');
- })
- }
- }
-
- }
- }
- })()
2、生成较大的doc
file/generate_larger_doc.js
- /**
- *
- * @description 拼接mysql字段的值,从中随机取值后,生成size比较大的doc文件
- */
- const fs = require('fs')
- const mysql_config = require('../config/mysql_config')
- const {connect, read} = require('../mysql/mysql');
-
- (async () => {
- const Mock = require('mockjs')
- let Random = Mock.Random
- let c = await connect(mysql_config.options)
- for (let j = 0; j < 1000; j++) {
- let start = j * 1000
- let end = (j + 1) * 1000
- let sql = `select * from test limit ${start},${end}`
- let arr = await read(c, sql)
- let name = Random.csentence(5, 15).replaceAll('。', '')
- for (let i in arr) {
- if (arr.hasOwnProperty(i)) {
- if (parseInt(i) / 1000 % 1 === 0 && parseInt(i) !== 0) {
- break
- } else {
- console.log(1)
- fs.writeFile(`${name}.doc`, JSON.stringify(arr[i]), {flag: 'a', encoding: 'utf8'}, err => {
- if (err) throw err;
- console.log('The file has been saved!');
- })
- }
- }
- }
- }
- })()
3、生成txt
file/generate_txt.js
- /**
- *
- * @description 拼接mysql字段的值,从中随机取值后,生成txt文件
- */
- const fs = require('fs')
- const mysql_config = require('../config/mysql_config')
- const {connect, read} = require('../mysql/mysql');
-
- (async () => {
- const Mock = require('mockjs')
- let Random = Mock.Random
- let c = await connect(mysql_config.options)
- for (let j = 0; j < 1000; j++) {
- let start = j * 1000
- let end = (j + 1) * 1000
- let sql = `select * from test limit ${start},${end}`
- let arr = await read(c, sql)
- let name = Random.csentence(5, 15).replaceAll('。', '')
- for (let i in arr) {
- if (arr.hasOwnProperty(i)) {
- if (parseInt(i) / 100 % 1 === 0 && parseInt(i) !== 0) {
- break
- } else {
- fs.writeFile(`${name}.txt`, JSON.stringify(arr[i]), {flag: 'a'}, err => {
- if (err) throw err;
- console.log('The file has been saved!');
- })
- }
- }
- }
- }
- })()
4、config/mysql_config.js
- module.exports = {
- options: {
- host: 'vm-mysql57.lan',
- user: 'root',
- password: 'wlh123456',
- database: 'data_jimi',
- insert_file: {
- table: 'file',
- path: 'D:\\target',
- field1: 'content',
- field2: 'filename'
- }
- },
- sql_group: {
- es_sql: 'select * from test limit 50000,50600',
- hbase_sql: '',
- mongo_sql: '',
- neo4j_sql: '',
- redis_sql: ''
- }
- }