New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/datastore

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/datastore

Cloud Datastore Client Library for Node.js

  • 4.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38K
decreased by-58.77%
Maintainers
1
Weekly downloads
 
Created

What is @google-cloud/datastore?

@google-cloud/datastore is a Node.js client library for Google Cloud Datastore, a NoSQL document database built for automatic scaling, high performance, and ease of application development. It allows you to interact with Google Cloud Datastore to perform operations such as creating, reading, updating, and deleting entities.

What are @google-cloud/datastore's main functionalities?

Create an Entity

This code sample demonstrates how to create and save a new entity in Google Cloud Datastore. It creates a 'Task' entity with a description and saves it to the datastore.

const { Datastore } = require('@google-cloud/datastore');
const datastore = new Datastore();

const taskKey = datastore.key('Task');

const task = {
  key: taskKey,
  data: {
    description: 'Buy milk'
  }
};

datastore.save(task)
  .then(() => {
    console.log(`Task ${taskKey.id} created successfully.`);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Retrieve an Entity

This code sample demonstrates how to retrieve an entity from Google Cloud Datastore using its key. It fetches a 'Task' entity by its ID and logs the result.

const { Datastore } = require('@google-cloud/datastore');
const datastore = new Datastore();

const taskKey = datastore.key(['Task', 'taskId']);

datastore.get(taskKey)
  .then(([task]) => {
    if (!task) {
      console.log('No task found.');
      return;
    }
    console.log('Task:', task);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Update an Entity

This code sample demonstrates how to update an existing entity in Google Cloud Datastore. It updates the description of a 'Task' entity.

const { Datastore } = require('@google-cloud/datastore');
const datastore = new Datastore();

const taskKey = datastore.key(['Task', 'taskId']);

const task = {
  key: taskKey,
  data: {
    description: 'Buy milk and bread'
  }
};

datastore.update(task)
  .then(() => {
    console.log(`Task ${taskKey.id} updated successfully.`);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Delete an Entity

This code sample demonstrates how to delete an entity from Google Cloud Datastore. It deletes a 'Task' entity by its key.

const { Datastore } = require('@google-cloud/datastore');
const datastore = new Datastore();

const taskKey = datastore.key(['Task', 'taskId']);

datastore.delete(taskKey)
  .then(() => {
    console.log(`Task ${taskKey.id} deleted successfully.`);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Other packages similar to @google-cloud/datastore

Keywords

FAQs

Package last updated on 09 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc