# @edgeros/eldb-client 

`@edgeros/eldb-client` is an etcdshim,  similar to `@edgeros/etcd3` support  `etcd` and `sqlite` as persistent engine.

`sqlite` will be supported in `v2`

* Support api:

  `KV`
  `Lease`
  `Watch`

# Quickstart

* Install
```
npm install --save @edgeros/eldb-client 
```

* Usage

`kv`,`watch`,`lease` api is like [etcd3](https://microsoft.github.io/etcd3/classes/namespace.html)

```javascript
// etcd
import { DBClient } from '@edgeros/eldb-client'

async function foo () {
  const options = {
    etcd: {
      hosts: '10.12.0.204:2379'
    }
  }
  const client =  new DBClient(options)
  await client.init()
  // kv
  await client.put('foo1').value('bar1'),
  await client.put('foo2').value('bar2'),
  await client.put('foo3').value('{"value":"bar3"}'),
  console.log(await client.get('foo1').string())
  console.log(await client.get('foo2').buffer())
  console.log(await client.get('foo3').json())

  // lease
  const lease = client.lease(100)
  await lease.put('leased').value('foo')
  await lease.revoke()

  // watch
  const watcher = await client.watch().key('foo1').watcher()
  watcher.on('connecting', () => console.log('connecting'))
  watcher.on('connected', () => console.log('connected'))
  watcher.on('put', (kv) => console.log('put', kv))
  watcher.on('delete', (kv) => console.log('delete', kv))
  await watcher.cancel()

  client.close()
}


```

# Versions

* v1: support etcd       (✔)
* v2: support sqlite     (...)
* v3: support db compact (...)

