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

Google Cloud Datastore Client Library for Node.js

0.2.0
Source
npm
Version published
Weekly downloads
177K
23.3%
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

google apis client

FAQs

Package last updated on 30 Aug 2016

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