0db-repl

中文文档
0.0.1发布于 2021/10/05MITCommonJS

0db REPL playground for testing 0db database.

原始使用文档
文档目录7 节
  1. 📥 Installation
  2. ℹ️ Usage
  3. Context Variables:
  4. 🚀 Development
  5. 🏭 Environment
  6. 🌑 Application
  7. 📃 License

🅾️ 0db REPL

NPM version NodeJS JavaScript Web

REPL playground for testing 0db.

This is a nodeJS REPL that comes with some handy context variables to easily play around with 0db on the command line.

Screenshot

📥 Installation

npm i 0db-repl -g

ℹ️ Usage

Launch using:

0db

Type help() to see a description of all available context variables.

Context Variables:

Context variables are objects and functions that are already defined and available for usage during the REPL session.

$0db

0db object.

🎯 Example:

► const myDb = await $0db("my-db.json")

db

A default instance using the default file ./db.json ready for use.

🎯 Example:

► await db("users").create({ name: "ambratolm" })

faker

Fake data generator to generate some realistic mock data. (See: Faker.JS)

🎯 Example:

► faker.name.firstName()
► faker.name.lastName()
► faker.name.gender()
► faker.internet.userName()
► faker.internet.email()
► faker.internet.password()
► await db("users").create({
    name: faker.internet.userName(),
    email: faker.internet.email(),
    password: faker.internet.password()
  })

gen

Built-in example data objects generator (using faker) that has some functions to generate example objects that can be added to database.

  • gen.user(count?) : Generates user objects.

    • Parameters:
      • count : Number, Optional. Number of objects to generate. Default: 1.
    • Returns an object if count <= 1, else an array of objects.

    user object is based on this schema:

    {
      name: String,
      firstName: String,
      lastName: String,
      gender: String,
      email: String,
      password: String,
      points: Number
    }
    

    🎯 Example:

    ► gen.user() // Returns 1 user object
    ► gen.user(100) // Returns an array of 100 user objects
    
    ► await db("users").create(gen.user())
    
  • gen.note(author?, count?) : Generates note objects.

    • Parameters:
      • author : String, Optional. Identifier for the author of the note (Expected to be the $id field of a created user object that exists in database).
      • count : Number, Optional. Number of objects to generate. Default: 1.
    • Returns an object if count <= 1, else an array of objects.

    note object is based on this schema:

    {
      author: String,
      title: String,
      content: String
    }
    

    🎯 Example:

    ► const user = await db("users").create(gen.user()) // Create a user item
    ► gen.note(user.$id) // Returns 1 note object
    ► gen.note(user.$id, 100) // Returns an array of 100 note objects
    
    ► const user = await db("users").create(gen.user())
    ► await db("notes").create(gen.note(user.$id))
    

cls

Clears screen.

🎯 Example:

► cls()

help

Shows a description of all context variables.

  • Parameters:
    • name : String, Optional. Name of a specific context object or function to show description for.

🎯 Example:

► help() // Shows all descriptions
► help("db") // Shows description only for "db" function
► help("gen") // Shows description only for "gen" object

🚀 Development

  1. Clone the repository.

    cd somewhere
    git clone https://github.com/practical-works/0db-repl.git
    cd 0db-repl
    
  2. Install dependencies: npm i

  3. Run:

    • npm run dev for development.
    • npm start for production.

💡 In development, you can type rs to manually restart. (See: Nodemon)

🏭 Environment

🌑 Application

📃 License

Licensed under MIT.

版本与发布记录

0db-repl 共发布 1 个版本,首次发布于 2021/10/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.1latest2021/10/055 年前

关于 0db-repl 的常见问题

0db-repl 是什么?

用于测试0db数据库的REPL游乐场。

如何安装 0db-repl?

在项目目录运行 npm install 0db-repl,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 0db,可以用 npx 0db 直接运行。

0db-repl 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/0db-repl 是否存在。

0db-repl 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

0db-repl 可以商用吗?

0db-repl 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

0db-repl 还在维护吗?

最新版本 0.0.1 发布于 2021/10/05(5 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/10/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。