node.js 数据库_Node.js中用于播种数据库的工具

node.js 数据库

In this post, I’ll be discussing some tools I’ve found and used for different projects of mine. Why would we want to seed a database? There are typically a couple of reasons to seed a database. First, having data in your database is typically helpful for tests that need to hit the database. The second reason to seed a database is to show off a project, for example, a portfolio piece or an internal demonstration of something you developed for your company.

在这篇文章中,我将讨论一些我发现并用于我的不同项目的工具。 我们为什么要播种数据库? 建立数据库的种子通常有两个原因。 首先,在数据库中存储数据通常有助于需要访问数据库的测试。 播种数据库的第二个原因是炫耀一个项目,例如,项目组合或您为公司开发的项目的内部演示。

There are two categories of tools I’m listing. A data-oriented tool, and a few avatars tools.

我列出了两类工具。 一个面向数据的工具,以及一些化身工具。

Starting with the data-oriented tool, an NPM package, Chance. I love the variety of data that this tool can generate. Need to randomly generate an address? Chance can do it. Need random sentences? No problem. There are many different things that Chance can generate. I strongly suggest you check their documentation for the wide, and I do mean wide, variety of things it can generate.

从面向数据的工具NPM包Chance开始 。 我喜欢此工具可以生成的各种数据。 需要随机生成一个地址吗? 机会可以做到。 需要随机句子吗? 没问题。 机会可以产生许多不同的东西。 我强烈建议您检查他们的文档的范围,我的意思是它可以生成各种各样的东西。

What I find helpful, especially when using Chance in code tests, you can set a seed value for the pseudorandom generator that Chance uses. This way every time you run your program, as long as you invoke Chance’s functions in the same order, you will get repeatable results.

我发现有帮助,特别是在代码测试中使用Chance时,可以为Chance使用的伪随机生成器设置种子值。 这样,每次运行程序时,只要以相同的顺序调用Chance的函数,您将获得可重复的结果。

Gravatar Logo
Gravatar logo
墓碑徽标

There is, however, one feature so far that I don’t like. That is Chance’s ability to generate avatar URLs. When invoked, it generates random Gravatar URLs that typically do not result in a meaningful avatar but rather the Gravatar logo as seen here on the left.

到目前为止,我不喜欢其中一项功能。 这就是Chance生成头像URL的能力。 调用时,它会生成随机的Gravatar URL,这些URL通常不会产生有意义的化身,而是会产生Gravatar徽标,如左图所示。

cute cartoon kitten

The next 3 tools are all static image generators. The intent is to be used as image placeholders typically for profiles. All 3 tools are simple RESTful APIs where a simple URL is all you need. The image on the left was generated by going to the following URL https://robohash.org/whatever.png?set=set4 in the browser and saving the image. Of course, we can do this programmatically too.

接下来的3个工具都是静态图像生成器。 该意图通常用作配置文件的图像占位符。 这3种工具都是简单的RESTful API,仅需一个简单的URL。 左侧的图像是通过在浏览器中转到以下URL https://robohash.org/whatever.png?set=set4并保存图像而生成的。 当然,我们也可以通过编程方式执行此操作。

What's nice is all of these APIs take in some value (in the example above, whatever) that will generate a unique image. The same image will be generated by the same phrase over and over again so it is repeatable. However, change that value and a completely different image will be generated.

什么是漂亮的是所有这些API的参加一些值(在上面的例子中, whatever ),将产生一个独特的形象。 相同的短语将一遍又一遍地生成相同的图像,因此它是可重复的。 但是,更改该值将生成完全不同的图像。

Image for post

Starting off with my favorite, RobotHash, with which I used to generate the image on the left. This site is my favorite as I just happen to like robots. The site, if you read the short documentation (right on the home page) will also allow you to create monsters, humans, and cats (that cute kitty above is an example).

从我最喜欢的RobotHash开始,我用它来在左侧生成图像。 这个网站是我的最爱,因为我碰巧喜欢机器人。 如果您阅读了简短的文档(在主页上右侧),则该网站还可以使您创建怪物,人类和猫(上面的可爱小猫就是一个例子)。

Image for post

Next up we have DiceBear Avatars. This tool has two notable features. First, it can generate ten categories of images (sprites) including this pixilated male image on the left, and yes they have a female option too. Notably one of the options, code, generates QR codes. The second feature, is they provide npm packages with lots of advanced options for each sprite.

接下来,我们有DiceBear头像 。 该工具具有两个显着功能。 首先,它可以生成十类图像(子画面),包括左侧的像素化男性图像,是的,它们也具有女性选项。 值得注意的是,其中一种代码选项可生成QR码。 第二个功能是,它们为npm程序包提供每个sprite大量的高级选项。

Image for post

Last but not least is Adorable Avatars. Of the three generators, this site has the least amount of options. Pretty much you get a square cartoonish face, such as this one on the left.

最后但并非最不重要的是可爱的化身 。 在这三个生成器中,此站点的选项最少。 您几乎会得到一张方形的卡通脸,例如左侧的这张脸。

Image for post

The last tool I want to mention is Cartoon Avatars. This is an npm package that will randomly select URLs that resolve to cartoon avatars. What I like about these is that they are human placeholders and I can select male or female as an option. What should be noted is these images are not randomly generated, but rather randomly selected. There are 129 male avatars and 114 female avatars. That I believe should be enough for most projects.

我要提到的最后一个工具是“ 卡通头像” 。 这是一个npm软件包,它将随机选择解析为卡通化身的URL。 我喜欢这些是人类占位符,我可以选择男性还是女性作为选项。 应该注意的是这些图像不是随机生成的,而是随机选择的。 有129个男性头像和114个女性头像。 我相信对于大多数项目来说就足够了。

翻译自: https://medium.com/@brainomite/tools-for-seeding-databases-in-node-js-72fb2f6c7320

node.js 数据库

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
node.js Windowv 上安装Node.js Windows 安装包(.msi) : 32 位安装包下载地址 : http://nodejs.org/dist/v0.10.26/node-v0.10.26-x86.msi 64 位安装包下载地址 : http://nodejs.org/dist/v0.10.26/x64/node-v0.10.26-x64.msi 安装步骤: 步骤 1 : 双击下载后的安装包 node-v0.10.26-x86.msi,如下所示: install-node-msi-version-on-windows-step1 步骤 2 : 点击以上的Run(运行),将出现如下界面: install-node-msi-version-on-windows-step2 步骤 3 : 勾选接受协议选项,点击 next(下一步) 按钮 : install-node-msi-version-on-windows-step3 步骤 4 : Node.js默认安装目录为 "C:\Program Files\nodejs\" , 你可以修改目录,并点击 next(下一步): install-node-msi-ve rsion-on-windows-step4 步骤 5 : 点击树形图标来选择你需要的安装模式 , 然后点击下一步 next(下一步) install-node-msi-version-on-windows-step5 步骤 6 :点击 Install(安装) 开始安装Node.js。你也可以点击 Back(返回)来修改先前的配置。 然后并点击 next(下一步): install-node-msi-version-on-windows-step6 安装过程: install-node-msi-version-on-windows-step7 点击 Finish(完成)按钮退出安装向导。 install-node-msi-version-on-windows-step8 检测PATH环境变量是否配置了Node.js,点击开始=》运行=》输入"cmd" => 输入命令"path",输出如下结果: PATH=C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Windows\system32; C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\; c:\python32\python;C:\MinGW\bin;C:\Program Files\GTK2-Runtime\lib; C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\nodejs\; C:\Users\rg\AppData\Roaming\npm 我们可以看到环境变量已经包含了C:\Program Files\nodejs\ 检查Node.js版本 node-version-test Windows 二进制文件 (.exe)安装 : 32 位安装包下载地址 : http://nodejs.org/dist/v0.10.26/node.exe 64 位安装包下载地址 : http://nodejs.org/dist/v0.10.26/x64/node.exe 安装步骤 步骤 1 : 双击下载的安装包 Node.exe ,将出现如下界面 : install-node-exe-on-windows-step1 点击 Run(运行)按钮将出现命令行窗口: install-node-exe-on-windows-step21 版本测试 进入 node.exe 所在的目录,如下所示: node-version 如果你获得以上输出结果,说明你已经成功安装了Node.js。 Linux上安装 Node.js Ubuntu 源码安装 以下部分我们将介绍在Ubuntu Linux下安装 Node.js 。 其他的Linux系统,如Centos等类似如下安装步骤。 在 Github 上获取 Node.js 源码: install-node-msi-version-on-linux-step1 install-node-msi-version-on-linux-step2 在完成下载后,将源码包名改为 'node'。 install-node-msi-version-on-linux-step3 修改目录权限: install-node-msi-version-on-linux-step4 使用 './configure' 创建编译文件。 install-node-msi-version-on-linux-step5 编译: make。 install-node-msi-version-on-linux-step6 完成安装: make install。 install-node-msi-version-on-linux-step7 最后我们输入'node --version' 命令来查看Node.js是否安装成功。 install-node-msi-version-on-linux-step8 Ubuntu apt-get命令安装 命令格式如下: sudo apt-get install nodejs sudo apt-get install npm centOS下安装nodejs 1、下载源码,你需要在http://nodejs.org/下载最新的Nodejs版本,本文以v0.10.24为例: cd /usr/local/src/ wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz 2、解压源码 tar zxvf node-v0.10.24.tar.gz 3、 编译安装 cd node-v0.10.24 ./configure --prefix=/usr/local/node/0.10.24 make make install 4、 配置NODE_HOME,进入profile编辑环境变量 vim /etc/profile 设置nodejs环境变量,在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL 一行的上面添加如下内容: #set for nodejs export NODE_HOME=/usr/local/node/0.10.24 export PATH=$NODE_HOME/bin:$PATH :wq保存并退出,编译/etc/profile 使配置生效 source /etc/profile 验证是否安装配置成功 node -v 输出 v0.10.24 表示配置成功 npm模块安装路径 /usr/local/node/0.10.24/lib/node_modules/ 注:Nodejs 官网提供了编译好的Linux二进制包,你也可以下载下来直接应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值