Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple key/value datastore methods #256

Closed
ryanseys opened this issue Oct 13, 2014 · 6 comments
Closed

Simple key/value datastore methods #256

ryanseys opened this issue Oct 13, 2014 · 6 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@ryanseys
Copy link
Contributor

Pardon my noob-ish request. As far as I understand, I cannot currently do simple key / value store functionality like due to the inherent complexity of the datastore key objects:

var key = "hello"; // string or number
var value = "world"; // string or number

datastore.set(key, value, function(err) {
  if(!err) {
    // success;
  } 
});

datastore.get("hello", function(err, val) {
  val; // "world"
});
@ryanseys
Copy link
Contributor Author

@pcostell

@beriberikix
Copy link
Contributor

@pcostell @jgeewax is this why an NDB layer would be useful?

@pcostell
Copy link
Contributor

It's definitely possible to build a simple key/value store on top of the Datastore. NDB however is not this. Even then you'd have to define a model with different properties.

Datastore is just a more complicated system than a key/value store. It support querying, consistency guarantees, and a large amount of unstructured data.

If you wanted to build your own wrapper, you could do something very simple like:

function KeyValueDatastore(dataset) {
  this.dataset = dataset;
}

// key is a string or int.
KeyValueDatastore.get = function(key, value, callback) {
  this.dataset.get(this.dataset.key(['KeyValue', key]), function(err, entity) {
    callback(err, 'value' in entity ? entity['value'] : None);
  }
}

// key is a string or int.
KeyValueDatastore.set = function(key, value, callback) {
  this.dataset.save({
    key : this.dataset.key(['KeyValue', key]),
    data :  {
      'value' : value
    },
    function(err, keys) {
      callback(err);
    }
  });
}

In terms of handling the key, I just chose a kind to put things into, then using the provided key as either the name or id.

@stephenplusplus
Copy link
Contributor

The above could be a good case for a gcloud extension from userland.

var gcloud = require('gcloud')({/*...*/});
var keystore = require('gcloud-keystore');

var dataset = keystore(gcloud.dataset());

dataset.set('company', 'yay');
dataset.get('company', function(err, value) {});

@stephenplusplus
Copy link
Contributor

@stephenplusplus
Copy link
Contributor

Going to close -- to anyone interested, try out gcloud-keystore!

@jgeewax jgeewax added api: datastore Issues related to the Datastore API. enhancement labels Feb 2, 2015
@jgeewax jgeewax added this to the Datastore Future milestone Feb 2, 2015
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
sofisl pushed a commit that referenced this issue Oct 13, 2022
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/7de5fca1-c450-46ed-b4bd-ed0a7f991ee4/targets

- [ ] To automatically regenerate this PR, check this box.

PiperOrigin-RevId: 361273630
Source-Link: googleapis/googleapis@5477122
sofisl pushed a commit that referenced this issue Nov 10, 2022
* updated CHANGELOG.md [ci skip]

* updated package.json [ci skip]

* updated samples/package.json [ci skip]
sofisl pushed a commit that referenced this issue Nov 11, 2022
* updated CHANGELOG.md

* updated package.json

* updated samples/package.json
sofisl pushed a commit that referenced this issue Nov 11, 2022
…ncy versions (#256)

This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/28f926df-4479-489a-b60f-ecf7782e1eb7/targets

- [ ] To automatically regenerate this PR, check this box.

Source-Link: googleapis/synthtool@fdd03c1
sofisl pushed a commit that referenced this issue Nov 11, 2022
The library is regenerated with gapic-generator-typescript v1.3.1.

Committer: @alexander-fenster
PiperOrigin-RevId: 372468161

Source-Link: googleapis/googleapis@75880c3

Source-Link: googleapis/googleapis-gen@77b1804
sofisl pushed a commit that referenced this issue Nov 11, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this issue Nov 11, 2022
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@types/node](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node) ([source](https://togithub.com/DefinitelyTyped/DefinitelyTyped)) | [`^16.0.0` -> `^18.0.0`](https://renovatebot.com/diffs/npm/@types%2fnode/16.18.3/18.11.9) | [![age](https://badges.renovateapi.com/packages/npm/@types%2fnode/18.11.9/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@types%2fnode/18.11.9/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@types%2fnode/18.11.9/compatibility-slim/16.18.3)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@types%2fnode/18.11.9/confidence-slim/16.18.3)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: Branch creation - "after 9am and before 3pm" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-media-translation).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4yNDEuMTEiLCJ1cGRhdGVkSW5WZXIiOiIzNC4xMS4xIn0=-->
sofisl pushed a commit that referenced this issue Nov 11, 2022
* fix: replaces old with current product doc location

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

6 participants