本文主要是介绍管理员数据生成,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
const mysql = require('../libs/mysql');
const password = require('../libs/password');(async ()=>{let db = await mysql;let name = 'blue';let pass = '123456';// 检查let rows = await db.query("SELECT * FROM admin_table WHERE username=?", [name]);if(rows.length>0) {console.log(`管理员账号已存在:${name}`);}else{await db.query("INSERT INTO admin_table (username,password) VALUES(?,?)", [name, password(pass)]);console.log('管理员添加成功');}
})();
好玩的东西
const readline = require('readline');let rl = readline.createInterface({input: process.stdin, // 标准输入流output: process.stdout, // 标准输出流
});rl.question('what is your name ', name=>{console.log('hi:', name)
})
add_admin.js:
const mysql = require('../libs/mysql');
const password = require('../libs/password');
const rl = require('../libs/rl');(async ()=>{let db = await mysql;while(1) {let name = await rl.questionAsync('admin username: ');if(!name){break;}// 检查let rows = await db.query("SELECT * FROM admin_table WHERE username=?", [name]);if(rows.length>0) {console.log(`管理员账号已存在:${name}`);}else{let pass = await rl.questionAsync('admin password: ');await db.query("INSERT INTO admin_table (username,password) VALUES(?,?)", [name, password(pass)]);console.log('管理员添加成功');}}rl.close();
})();
这篇关于管理员数据生成的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!