매일매일 IT

[NoSQL] LevelDB 본문

Database

[NoSQL] LevelDB

Teeeeeeemo 2017. 7. 25. 15:17
  • Key-Value 형식의 데이터 store 중 하나
  • GOOGLE 개발
  • C++로 만들어졌지만 많은 프로그래밍 언어로 사용 가능.
  • 구글 크롬에서 IndexedDB를 구현하기 위해 LevelDB를 만들었다.
  • IndexedDB : HTML5 사양 중 하나
  • LevelDB는 임베디드용으로 사용할 수 있는 DB로 다루기 용이 
LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.
  • db.createKeyStream([options])

    KeyStream is a ReadStream where the 'data' events are simply the keys from the database so it can be used like a traditional stream rather than an object stream.

    You can obtain a KeyStream either by calling the createKeyStream() method on a LevelUP object or by passing passing an options object to createReadStream() with keys set to true and values set to false.

    db.createKeyStream()
      .on('data', function (data) {
        console.log('key=', data)
      })
    
    // same as:
    db.createReadStream({ keys: true, values: false })
      .on('data', function (data) {
        console.log('key=', data)
      })



  • db.createReadStream([options])

  • You can obtain a ReadStream of the full database by calling the createReadStream() method. The resulting stream is a complete Node.js-style Readable Stream where 'data' events emit objects with 'key' and 'value' pairs.

    db.createReadStream()
      .on('data', function (data) {
        console.log(data.key, '=', data.value)
      })
      .on('error', function (err) {
        console.log('Oh my!', err)
      })
      .on('close', function () {
        console.log('Stream closed')
      })
      .on('end', function () {
        console.log('Stream closed')
      })

    The standard pause()resume() and destroy() methods are implemented on the ReadStream, as is pipe() (see below). 'data', 'error''end' and 'close' events are emitted.

    Additionally, you can supply an options object as the first parameter to createReadStream() with the following options:

    • 'start': the key you wish to start the read at. By default it will start at the beginning of the store. Note that the start doesn't have to be an actual key that exists, LevelDB will simply find the next key, greater than the key you provide.

    • 'end': the key you wish to end the read on. By default it will continue until the end of the store. Again, the enddoesn't have to be an actual key as an (inclusive) <=-type operation is performed to detect the end. You can also use the destroy() method instead of supplying an 'end' parameter to achieve the same effect.

    • 'reverse' (boolean, default: false): a boolean, set to true if you want the stream to go in reverse order. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek.

    • 'keys' (boolean, default: true): whether the 'data' event should contain keys. If set to true and 'values'set to false then 'data' events will simply be keys, rather than objects with a 'key' property. Used internally by the createKeyStream() method.

    • 'values' (boolean, default: true): whether the 'data' event should contain values. If set to true and 'keys' set to false then 'data' events will simply be values, rather than objects with a 'value' property. Used internally by the createValueStream() method.

    • 'limit' (number, default: -1): limit the number of results collected by this stream. This number represents a maximum number of results and may not be reached if you get to the end of the store or your 'end' value first. A value of -1 means there is no limit.

    • 'fillCache' (boolean, default: false): wheather LevelDB's LRU-cache should be filled with data read.


요기서 참고 하기 : https://github.com/Level/levelup


'Database' 카테고리의 다른 글

[SQL] ROUND 함수  (0) 2017.12.19
[SQL] Case 문  (0) 2017.12.15
Comments