1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/was666-as-db

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
Внести вклад в разработку кода
Синхронизировать код
Отмена
Подсказка: Поскольку Git не поддерживает пустые директории, создание директории приведёт к созданию пустого файла .keep.
Loading...
README.md

as-db

as-db 是一个 node 本地 JSON 数据库

数据库创建/获取对象

// 引入as-db.js
const db = require('./as-db')

// 数据库创建/获取对象(文件不存在时会自动创建)
const user = db.create('user')

Usage 使用 (index.js 是示例)

// require the s-db.js
// 引入as-db.js
const db = require('./as-db')

// get a database object
// 得到数据库对象
const user = db.create('user')

// Next, you just need to operate on the user object
// 接下来你只需要对user对象进行增删改查操作即可

// set a property
// 设置属性
user.name = 'as-yyds'
user.age = 18
user.hobbies = ['eating', 'sleaping', 'playing Peas']
user.hobbies.push('fish')
user.gender = true
user.address = {
    country: 'China',
    city: 'Beijing'
}
user.address.city = 'fujian'
// user.json
{
    "name": "as-yyds",
    "age": 18,
    "hobbies": [
        "eating",
        "sleaping",
        "playing Peas",
        "fish"
    ],
    "address": {
        "country": "China",
        "city": "fujian"
    },
    "gender": true
}
// get a property
// 读取属性
user.name // 'as-yyds'
user.age // 18
user.hobbies // ['eating', 'sleaping', 'playing Peas']
user.gender // true
user.address // {country: 'China', city: 'Beijing'}
user.address.city // 'fujian'

Methods 方法

db.create([dbName, config])

  • dbName {String} File name. If this parameter is not passed in, the current timestamp will be used as the file name. If the file does not exist, a new file will be created. If the file exists, the contents of the file will be read. 文件名,不传入该参数将把当前时间戳作为文件名。文件不存在则会创建一个新文件,若文件存在则读取该文件内容。

  • config {object} Configuration object. 配置对象。

    • path {String} Database file storage path. 数据库文件存放路径。It should be an absolute path. 推荐传入一个绝对路径 Default: ./db/
    • data {object} Initial data. If this parameter is passed in, the data will be written to the file. 初始数据,如果对该属性赋值会把数据写入到文件中(如果文件已存在会覆盖文件内容)。

Комментарии ( 0 )

Вы можете оставить комментарий после Вход в систему

Введение

Описание недоступно Развернуть Свернуть
MIT
Отмена

Обновления

Пока нет обновлений

Участники

все

Недавние действия

Загрузить больше
Больше нет результатов для загрузки
1
https://api.gitlife.ru/oschina-mirror/was666-as-db.git
git@api.gitlife.ru:oschina-mirror/was666-as-db.git
oschina-mirror
was666-as-db
was666-as-db
master