A Key-value Is A in-memory Storage for Deno

Storage

A key-value is a in-memory storage for deno.

import { LocalStorage } from "https://deno.land/x/storage@0.0.5/mod.ts"

const storage = new LocalStorage<string>();

// set data
storage.set({
  key: "value",
  key2: "value2"
})
storage.set([
  ["key", "value"],
  ["key2" ,"value2"]
])
storage.set("key","value")

// get data
// `note` get return shalow copy 
storage.get("key") // "value"
storage.get(["key","key2"]) // ["value","value2"]
storage.keys() // ["key", "key2"]
storage.values() // ["value", "value2"]
storage.entries() // [["key", "value"], ["key2", "value2"]]

// check and delete data
storage.delete("key2")
storage.has("key2") // false
storage.clear() // {}

const storage2 = new LocalStorage<{prop : string}>();
// update data 
storage2.set("ID", data => {
   data ?? = { prop: 'value' } // default data
   data.prop = "newValue";
   return data; // update data 
})

// sava data
await storage.save();
await storage2.save();

Download Details:

Author: Rohan-ult

Source Code: https://github.com/Rohan-ult/deno_storage

#deno #nodejs #node #javascript

What is GEEK

Buddha Community

A Key-value Is A in-memory Storage for Deno

Java: How to Get Keys and Values from a Map

Introduction

Key-value stores are essential and often used, especially in operations that require fast and frequent lookups. They allow an object - the key - to be mapped to another object, the value. This way, the values can easily be retrieved, by looking up the key.

In Java, the most popular Map implementation is the HashMap class. Aside from key-value mapping, it’s used in code that requires frequest insertions, updates and lookups. The insert and lookup time is a constant O(1).

In this tutorial, we’ll go over how to get the Keys and Values of a map in Java.

#java #java: how to get keys and values from a map #keys #map #values #how to get keys and values from a map

Julia Bindings to KyotoCabinet Library (key Value Storage)

Julia binding for KyotoCabinet

This package provides bindings for KyotoCabinet key-value storage.

Installation

Pkg.add("KyotoCabinet")

Generic interface

using KyotoCabinet

To open database, use open method:

db = open("db.kch", "r")
# db::Dict{Array{Uint8,1},Array{Uint8,1}}
close(db)

There is also bracketed version:

open(Db{K,V}(), "db.kch", "w+") do db
  # db::Dict{K,V}
  # do stuff...
end

Db object implements basic collections and Dict methods.

open(Db{String,String}(), "db.kch", "w+") do db
  # Basic getindex, setindex! methods
  db["a"] = "1"
  println(db["a"])

  # Dict methods also implemented:
  # haskey, getkey, get, get!, delete!, pop!
  if (!haskey(db, "x"))
    x = get(db, "x", "default")
    y = get!(db, "y", "set_value_if_non_exists")
  end
end

Support iteration over records, keys and values:

for (k, v) = db
  println("k=$k v=$v")
end
for k = keys(db)
  println("k=$k")
end

Serialization/Deserialization

KyotoCabinet treats keys and values as byte arrays. To make it work with arbitrary types, one needs to define pack/unpack methods.

immutable K
  x::Int
end

immutable V
  a::Int
  b::String
end

function KyotoCabinet.pack(k::K)
  io = IOBuffer()
  write(io, int32(k.x))
  takebuf_array(io)
end
function KyotoCabinet.unpack(T::Type{K}, buf::Array{Uint8,1})
  io = IOBuffer(buf)
  x = read(io, Int32)
  K(int(x))
end

function KyotoCabinet.pack(v::V)
  io = IOBuffer()
  write(io, int32(v.a))
  write(io, int32(length(v.b)))
  write(io, v.b)
  takebuf_array(io)
end
function KyotoCabinet.unpack(T::Type{V}, buf::Array{Uint8,1})
  io = IOBuffer(buf)
  a = read(io, Int32)
  l = read(io, Int32)
  b = bytestring(read(io, Uint8, l))
  V(int(a), b)
end

After that these types can be used as keys/values:

open(Db{K, V}(), "db.kch", "w+") do db
  db[K(1)] = V(1, "a")
  db[K(1999999999)] = V(2, repeat("b",100))
end

k = K(1)
println(db[k])

KyotoCabinet specific

There are also KyotoCabinet specific methods.

Database info

# Get the path of the database file
p = path(db)

Compare-and-swap

cas(db::Db, key, old, new)

Compare-and-swap method. Update the value only if it's in the expected state. Returns true if value have been updated.

cas(db, "k", "old", "new") # update only if db["k"] == "old"
cas(db, "k", "old", ())    # remove record, only if db["k"] == "old"
cas(db, "k", (), "new")    # add record, only if "k" not in db

Bulk operations

# Updates records in one operation, atomically if needed.
bulkset!(db, ["a" => "1", "b" => "2"], true)

# Removes records in one operation, atomically if needed.
bulkdelete!(db, ["a", "b"], true)

Download Details:

Author: Tuzzeg
Source Code: https://github.com/tuzzeg/kyotocabinet.jl 
License: View license

#julia #key #value #storage 

A Key-value Is A in-memory Storage for Deno

Storage

A key-value is a in-memory storage for deno.

import { LocalStorage } from "https://deno.land/x/storage@0.0.5/mod.ts"

const storage = new LocalStorage<string>();

// set data
storage.set({
  key: "value",
  key2: "value2"
})
storage.set([
  ["key", "value"],
  ["key2" ,"value2"]
])
storage.set("key","value")

// get data
// `note` get return shalow copy 
storage.get("key") // "value"
storage.get(["key","key2"]) // ["value","value2"]
storage.keys() // ["key", "key2"]
storage.values() // ["value", "value2"]
storage.entries() // [["key", "value"], ["key2", "value2"]]

// check and delete data
storage.delete("key2")
storage.has("key2") // false
storage.clear() // {}

const storage2 = new LocalStorage<{prop : string}>();
// update data 
storage2.set("ID", data => {
   data ?? = { prop: 'value' } // default data
   data.prop = "newValue";
   return data; // update data 
})

// sava data
await storage.save();
await storage2.save();

Download Details:

Author: Rohan-ult

Source Code: https://github.com/Rohan-ult/deno_storage

#deno #nodejs #node #javascript

Einar  Hintz

Einar Hintz

1593244500

Storage in Android - How to save data and files in Android? - DataFlair

Storage in Android

Android uses a file system that is like a disk-based file system of other platforms. The Android system provides different options to save application data:

  • Application-specific storage in Android
  • Shared storage in Android
  • Preferences in Android
  • Databases in Android

Let us go through these all one by one.

1. Android Application-specific storage

In this, the stored data is meant only for a specific application’s use. It is stored either in a dedicated directory inside the internal storage or in external storage. The sensitive data, that is specific to the app and shall not be accessible to other apps is generally stored in Internal Storage. There are certain things about it that are:

a. To access it, we have two ways:

  • Internal Storage
  • getFilesDir() or getCacheDir()
  • External Storage
  • getExternalFilesDir() or getExternalCacherDir()

b. Permission is not required for Internal Storage as well as for External Storage. When considering external storage, we do not need permission for Android version 4.4(API level 19) or higher.

c. If the app data is in internal storage, other apps cannot access it. If the data is in external storage, files can be accessed by other apps.

d. If the application is uninstalled by any means, the data files also get deleted.

2. Shared Storage in Android

In this, the stored data is meant to be shared among other apps as well. It includes data such as multimedia, documents, etc. There are certain things about it that are:

a. Access the data with MediaStore API and Storage Access Framework.

b. To read the media file use these permissions: READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE for Android 10 or higher.

c. You can access the media files by other files through READ_EXTERNAL_STORAGE and the document files, through system file picker.

d. If you uninstall the app, the data would not be deleted from the External Storage.

3. Android Preferences

They store the data in a private database. It stores the data in the form of a key-value pair. There are certain things about it that are:

a. Data is stored in a key-value pair.

b. It can be accessed through the Jetpack preference library.

c. Data from this cannot be accessed through other applications.

d. When you uninstall the app, the data gets deleted.

4. Android Databases

In this, the data is stored as structured data in a private database. For that, it uses the Room persistence library. There are certain things about it that are:

a. It has structured data

b. To access the data use Room persistence library

c. No other application can access the data

d. On the uninstallation of the application, the data gets deleted too.

#android tutorials #android storage #external storage in android #internal storage in android #storage in android

Elian  Harber

Elian Harber

1659796500

Skate: A Personal Key Value Store

Skate

A personal key-value store. 

Skate is simple and powerful. Use it to save and retrieve anything you’d like—even binary data. It’s fully encrypted, backed up to the cloud (that you can self-host if you want) and can be synced with all your machines.

# Store something (and sync it to the network)
skate set kitty meow

# Fetch something (from the local cache)
skate get kitty

# What’s in the store?
skate list

# Pull down the latest data
skate sync

# Spaces are fine
skate set "kitty litter" "smells great"

# You can store binary data, too
skate set profile-pic < my-cute-pic.jpg
skate get profile-pic > here-it-is.jpg

# Unicode also works, of course
skate set 猫咪 喵
skate get 猫咪

# For more info
skate --help

# Do creative things with skate list
skate set penelope marmalade
skate set christian tacos
skate set muesli muesli

skate list | xargs -n 2 printf '%s loves %s.\n'

Installation

Use a package manager:

# macOS or Linux
brew tap charmbracelet/tap && brew install charmbracelet/tap/skate

# Arch Linux (btw)
pacman -S skate

# Nix
nix-env -iA nixpkgs.skate

# Debian/Ubuntu
echo 'deb [trusted=yes] https://repo.charm.sh/apt/ /' | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install skate

# Fedora
echo '[charm]
name=Charm
baseurl=https://repo.charm.sh/yum/
enabled=1
gpgcheck=0' | sudo tee /etc/yum.repos.d/charm.repo
sudo yum install skate

Or download it:

  • Packages are available in Debian and RPM formats
  • Binaries are available for Linux, macOS, and Windows

Or just install it with go:

go install github.com/charmbracelet/skate@latest

Other Features

Databases

Sometimes you’ll want to separate your data into different databases:

# Database are automatically created on demand
skate set secret-boss-key@work-stuff password123

# Most commands accept a @db argument
skate set "office rumor"@work-stuff "penelope likes marmalade"
skate get "office rumor"@work-stuff
skate list @work-stuff

# Wait, what was that db named?
skate list-dbs

# Oh no, the boss is coming!
skate reset @work-stuff

Linking

One of the most powerful features of Skate is its ability to link two machines together so they have access to the same data. To link two machines together just run:

skate link

And follow the instructions. Keep in mind that you'll need access to both machines.

Syncing

When you run skate set, data is encrypted and synced to the network. When you get, however, data is loaded from the local cache. To fetch any new data from the server just run skate sync.

Examples

Here are some of our favorite ways to use skate.

Keep secrets out of your scripts

skate set gh_token GITHUB_TOKEN

#!/bin/bash
curl -su "$1:$(skate get gh_token)" \
    https://api.github.com/users/$1 \
    | jq -r '"\(.login) has \(.total_private_repos) private repos"'

Keep passwords in their own database

skate set github@password.db PASSWORD
skate get github@password.db

Use scripts to manage data

#!/bin/bash
skate set "$(date)@bookmarks.db" $1
skate list @bookmarks.db

What do you use skate for? Let us know.

Self-Hosting

Skate is backed by the Charm Cloud. By default it will use the Charm hosted cloud, but it’s incredibly easy to self-host, even if that’s just on your local network. For details, see the Charm docs.

Hey, Developers

Skate is built on charm/kv. If you’d like to build a tool that includes a user key value store, check it out. Skate has the same functionality as charm kv, but it uses a separate database.

FAQ

Skate is built off of Charm FS. Refer to its FAQ for more info.

Feedback

We’d love to hear your thoughts on this project. Feel free to drop us a note!


Part of Charm.

The Charm logo

Charm热爱开源 • Charm loves open source

Author: Charmbracelet
Source Code: https://github.com/charmbracelet/skate 
License: MIT license

#go #golang #key #value