https://github.com/Level/levelup

A node.js wrapper for abstract-leveldown compliant stores

一个为实现抽象leveldown兼容存储器的node.js封装器

levelup

Introduction

Fast and simple storage. A Node.js wrapper for abstract-leveldown compliant stores, which follow the characteristics of LevelDB.

快速简单存储。一个为实现抽象leveldown兼容存储器的node.js封装器,遵循了LevelDB的特性

LevelDB is a simple key-value store built by Google. It's used in Google Chrome and many other products. LevelDB supports arbitrary byte arrays as both keys and values, singular getput and delete operations, batched put and delete, bi-directional iterators and simple compression using the very fast Snappy algorithm.

LevelDB是一个Google构建的简单的键值存储。在Google Chrome和其他产品中被使用。LevelDB支持抽象字节数组作为键和值,单一getput delete操作,批处理的put 和delete操作,双向迭代和使用快速Snappy
算法进行简单压缩

LevelDB stores entries sorted lexicographically by keys. This makes the streaming interface of levelup - which exposes LevelDB iterators as Readable Streams - a very powerful query mechanism.

LevelDB存储按照键的字母顺序进行排序的条目。这构造了levelup的流接口-暴露了levelup作为可读流的迭代器-一个十分有效的查询机制

The most common store is leveldown which provides a pure C++ binding to LevelDB. Many alternative stores are availablesuch as level.js in the browser or memdown for an in-memory store. They typically support strings and Buffers for both keys and values. For a richer set of data types you can wrap the store with encoding-down.

最普遍的存储器是提供了存C++链接到LevelDB的leveldown。有很多交替存储是可用的,如在浏览器中的level.js,或者是内存存储的memdown.他们的键和值基本上之处字符串和Buffers类型。对于更丰富的数据类型集,你可以使用encoding-down来封装该存储

The level package is the recommended way to get started. It conveniently bundles levelupleveldown and encoding-down. Its main export is levelup - i.e. you can do var db = require('level').

level包是推荐的入门方法。它有着levelupleveldownencoding-down三部分。

主要的接口是level-比如使用var db = require('level')

Supported Platforms支持平台

We aim to support Active LTS and Current Node.js releases as well as browsers. For support of the underlying store, please see the respective documentation.

我们的目的是支持可用的LTS和当前的node.js以及浏览器。为了支持下面的存储,请查看相应的文档

Usage使用

If you are upgrading: please see UPGRADING.md.

如果更新:请看UPGRADING.md

First you need to install levelup! No stores are included so you must also install leveldown (for example).

首先安装levelup!没有包含的存储器,所有还要安装leveldown

$ npm install levelup leveldown

All operations are asynchronous. If you do not provide a callback, a Promise is returned.

所有操作都是异步的。如果你么有提供回调函数,那么将返回一个Promise

var levelup = require('levelup')
var leveldown = require('leveldown') // 1) Create our store,创建存储器
var db = levelup(leveldown('./mydb')) // 2) Put a key & value,存储键name&值levelup
db.put('name', 'levelup', function (err) {
if (err) return console.log('Ooops!', err) // some kind of I/O error // 3) Fetch by key,通过键name获取值levelup
db.get('name', function (err, value) {
if (err) return console.log('Ooops!', err) // likely the key was not found // Ta da!
console.log('name=' + value)
})
})
 

API

详细内容看本博客Level/levelup-2-API

Promise Support

levelup ships with native Promise support out of the box.

带有本地Promise的levelup支持开箱即用

Each function accepting a callback returns a promise if the callback is omitted. This applies for:

每一个接受回调函数的函数,在回调函数被省略时返回promise。其应用在:

  • db.get(key[, options])
  • db.put(key, value[, options])
  • db.del(key[, options])
  • db.batch(ops[, options])
  • db.batch().write()

The only exception is the levelup constructor itself, which if no callback is passed will lazily open the underlying store in the background.

唯一的特例是levelup自己的构造函数,如果没有回调函数将懒得在后台打开底层的存储器

Example:

var db = levelup(leveldown('./my-db'))

db.put('foo', 'bar')
.then(function () { return db.get('foo') })
.then(function (value) { console.log(value) })
.catch(function (err) { console.error(err) })

Or using async/await:

const main = async () => {
const db = levelup(leveldown('./my-db')) await db.put('foo', 'bar')
console.log(await db.get('foo'))
}

Events事件

levelup is an EventEmitter and emits the following events.

Event Description Arguments
put Key has been updated key, value (any)
del Key has been deleted key (any)
batch Batch has executed operations (array)
opening Underlying store is opening -
open Store has opened -
ready Alias of open -
closing Store is closing -
closed Store has closed. -

For example you can do:

db.on('put', function (key, value) {
console.log('inserted', { key, value })
})

Extending

A list of Level modules and projects can be found in the wiki. We are in the process of moving all this to awesome.

在wiki中可以找到一个级别模块和项目列表。我们正在把这一切变得更棒

Multi-process Access

Stores like LevelDB are thread-safe but they are not suitable for accessing with multiple processes. You should only ever have a store open from a single Node.js process. Node.js clusters are made up of multiple processes so a levelup instance cannot be shared between them either.

像LevelDB的存储器是线程安全的,但是当访问多进程时它是不适用的。你应该只从单Node.js进程打开该存储。Node.js集群由多进程组成,所以levelup实例也不能够在他们之间共享

See the aformentioned wiki for modules like multilevel, that may help if you require a single store to be shared across processes.

有关multilevel之类的模块,请参阅规范的wiki,如果您需要跨进程共享单个存储,这可能会有所帮助。

 

Level/levelup-1-简介的更多相关文章

  1. Level/levelup-2-API

    https://github.com/Level/levelup Special Notes What happened to db.createWriteStream() levelup(db[, ...

  2. 超实用压力测试工具-ab工具

    在学习ab工具之前,我们需了解几个关于压力测试的概念 吞吐率(Requests per second)概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求 ...

  3. Jtree (节点的渲染+资源管理器)

    我们的还是自定义的Jtree的类: package jtree.customNode; import java.io.File; import javax.swing.JTree; import ja ...

  4. jtree(选择框)

    jtree一般的用法是: 1. 展示电脑中文件的层次结构,如图所示. 具体的代码: package jtree; import java.io.File; import javax.swing.JTr ...

  5. RING0,RING1,RING2,RING3

    Intel的CPU将特权级别分为4个级别:RING0,RING1,RING2,RING3.Windows只使用其中的两个级别RING0和RING3,RING0只给操作系统用,RING3谁都能用.如果普 ...

  6. Vue2 实现树形菜单(多级菜单)功能模块

    结构示意图 ├── index.html ├── main.js ├── router │ └── index.js # 路由配置文件 ├── components # 组件目录 │ ├── App. ...

  7. ab压测工具

    在学习ab工具之前,我们需了解几个关于压力测试的概念 吞吐率(Requests per second)概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求 ...

  8. express操作数据库

    Express 首页 入门 使用指南 API 中文手册 进阶话题 有用的资源 集成数据库 为 Express 应用添加连接数据库的能力,只需要加载相应数据库的 Node.js 驱动即可.这里将会简要介 ...

  9. ab(http)与abs(https)压测工具

    在学习ab工具之前,我们需了解几个关于压力测试的概念 吞吐率(Requests per second) 概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请 ...

随机推荐

  1. [linux] shell脚本编程-xunsearch安装脚本学习

    安装脚本setup.sh #!/bin/sh # FULL fast install/upgrade script # See help message via `--help' # $Id$ # s ...

  2. [javaSE] GUI(事件监听机制)

    外部动作——>事件源(组件)——>事件对象——>监听器 获取Frame对象,与上节一样 调用Frame对象的addWindowListener()方法,参数:WindowListen ...

  3. Java开发相关官方存档下载地址

    前言 集中收藏Java开发中需要用到的常用下载地址 jdk Java SE 最新下载 | Oracle 技术网 : http://www.oracle.com/technetwork/cn/java/ ...

  4. SSM框架文件远程服务器下载

    1.首先你必须要建立连接 获取URL的输入流 2.之后就是文件读取和写入了 3.还有就是设置响应头,响应码等 代码 @RequestMapping("/fileDownLoad") ...

  5. CodeForces 598B(循环数组)

    对于循环数组的问题,就是找偏移K后位置 偏移后位置=起始位置+(相对位置+K)%(长度+1) #include <iostream> #include <string> #in ...

  6. MapReduce学习

    参考文章 参考文章2 shuffle的过程分析 Hadoop学习笔记:MapReduce框架详解 谈mapreduce运行机制,可以从很多不同的角度来描述,比如说从mapreduce运行流程来讲解,也 ...

  7. 工作经验:mybatis 处理 oracle Long 类型

    前言:mybatis 接收 oracle 中 LONG 类型的,报错:无效的列类型: getCLOB not implemented for class oracle.jdbc.driver.T4CL ...

  8. Web安全相关(五):SQL注入(SQL Injection)

    简介 SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,其主要原因是程序没有细致地过滤用户输入的数据 ...

  9. C#学习笔记-原型模式

    题目:编写基本的简历. 实现: 创建基本的Resume类,然后主函数通过实例化Resume来写简历即可. Resume类: class Resume { private string name; pr ...

  10. React Native中的远程调试是不可靠的

    一.原因 当您发现rn app在关闭远程调试后,一些功能无法正常工作时,这很可能是由于设备上的JavaScript执行环境与远程调试器之间的细微差别造成的. 例如,日期问题,Date构造函数似乎接受C ...