1.0.3 • Published 3 years ago

etcd3-json v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

etcd3-json

Etcd supports string values. You can keep json or array objects in etcd server with being stringified and can get them parsed.

This lib exports client object from Etcd3 class to use that framework natively also.

Install

npm i etcd3-json

in test.js file can be seen an example

// You can get client object for native use
const { putValue, getValue, getAll, client } = require("./services/etcd3");

(async ()=>{
    const person = {
        name: "john",
        surname: "snow",
        age: 4
    }
    const people = [ person ]

    // Put keys
    await putValue("foo", "bar");
    // You can put object stringified
    await putValue("person", person);
    await putValue("people", people);

    // Get keys
    const fooValue = await getValue("foo");
    const personValue = await getValue("person");
    const peopleValue = await getValue("people");
    // Get all
    const all = await getAll();

    console.log({fooValue, personValue, peopleValue});
/*   expected result
    {
        fooValue: 'bar',
        personValue: { name: 'john', surname: 'snow', age: 4 },
        peopleValue: [ { name: 'john', surname: 'snow', age: 4 } ]
    }
 */
//Delete one
    await delKey("foo");
    const _fooValue = await getValue("foo");
    console.log({_fooValue})

/*  expected result
    { _fooValue: {} }
 */

    // You can use client object from Etcd3 to use natively
    await client.delete().all();
    const allAfterDel = await client.getAll();
    console.log({allAfterDel});
/*  expected result
    { allAfterDel: {} }

 */
})()
1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago