Idiomatic class for interacting with Cloud Datastore. Uses the lower-level class under the hood.
In addition to the constructor options shown here, the Datastore class constructor accepts the same options accepted by .
The Datastore Emulator
Make sure you have the gcloud SDK installed , then run:
$ gcloud beta emulators datastore start --no-legacy
You will see the following printed:
\[datastore\] API endpoint: http://localhost:8005 \[datastore\] If you are using a library that supports the DATASTORE\_EMULATOR\_HOST environment variable, run: \[datastore\] \[datastore\] export DATASTORE\_EMULATOR\_HOST=localhost:8005 \[datastore\] \[datastore\] Dev App Server is now running.
Set that environment variable and your localhost Datastore will automatically be used. You can also pass this address in manually with apiEndpoint
.
Additionally, DATASTORE_PROJECT_ID
is recognized. If you have this set, you don't need to provide a projectId
.
{DatastoreRequest}
[Cloud Datastore Concepts Overview] https://cloud.google.com/datastore/docs/concepts/overview
Inheritance
DatastoreRequest > DatastorePackage
@google-cloud/datastore!Constructors
(constructor)(options)
constructor
(
options
?:
DatastoreOptions
);
Constructs a new instance of the Datastore
class
Type | Name | Description |
---|---|---|
options |
Properties
auth
auth
:
GoogleAuth
;
Type | Description |
---|---|
GoogleAuth |
baseUrl_
baseUrl_
?:
string
;
Type | Description |
---|---|
string |
clients_
clients_
:
Map<string
,
ClientStub
> ;
Type | Description |
---|---|
Map <string, ClientStub > |
customEndpoint_
customEndpoint_
?:
boolean
;
Type | Description |
---|---|
boolean |
DatastoreRequest
DatastoreRequest
:
typeof
DatastoreRequest
;
DatastoreRequest class.
Datastore.DatastoreRequest DatastoreRequest {constructor}
Type | Description |
---|---|
typeof DatastoreRequest |
defaultBaseUrl_
defaultBaseUrl_
:
string
;
Type | Description |
---|---|
string |
KEY
KEY
:
typeof
entity
.
KEY_SYMBOL
;
Type | Description |
---|---|
typeof entity.KEY_SYMBOL |
KEY
static
KEY
:
typeof
entity
.
KEY_SYMBOL
;
Access the Key from an Entity object.
Datastore#KEY {symbol}
Type | Description |
---|---|
typeof entity.KEY_SYMBOL |
MORE_RESULTS_AFTER_CURSOR
MORE_RESULTS_AFTER_CURSOR
:
string
;
Type | Description |
---|---|
string |
MORE_RESULTS_AFTER_CURSOR
static
MORE_RESULTS_AFTER_CURSOR
:
string
;
This is one of three values which may be returned from , , and as info.moreResults
.
There *may* be more results after the specified end cursor.
{string}
Type | Description |
---|---|
string |
MORE_RESULTS_AFTER_LIMIT
MORE_RESULTS_AFTER_LIMIT
:
string
;
Type | Description |
---|---|
string |
MORE_RESULTS_AFTER_LIMIT
static
MORE_RESULTS_AFTER_LIMIT
:
string
;
This is one of three values which may be returned from , , and as info.moreResults
.
There *may* be more results after the specified limit.
{string}
Type | Description |
---|---|
string |
namespace
namespace
?:
string
;
Type | Description |
---|---|
string |
NO_MORE_RESULTS
NO_MORE_RESULTS
:
string
;
Type | Description |
---|---|
string |
NO_MORE_RESULTS
static
NO_MORE_RESULTS
:
string
;
This is one of three values which may be returned from , , and as info.moreResults
.
There are no more results left to query for.
{string}
Type | Description |
---|---|
string |
options
options
:
DatastoreOptions
;
Type | Description |
---|---|
DatastoreOptions |
port_
port_
?:
number
;
Type | Description |
---|---|
number |
Query
Query
:
typeof
Query
;
Query class.
Datastore.Query Query {constructor}
Type | Description |
---|---|
typeof Query |
Transaction
Transaction
:
typeof
Transaction
;
Transaction class.
Datastore.Transaction Transaction {constructor}
Type | Description |
---|---|
typeof Transaction |
Methods
createQuery(kind)
createQuery
(
kind
?:
string
)
:
Query
;
Type | Name | Description |
---|---|---|
string
|
kind |
Type | Description |
---|---|
Query |
createQuery(kind)
createQuery
(
kind
?:
string
[])
:
Query
;
Type | Name | Description |
---|---|---|
string[]
|
kind |
Type | Description |
---|---|
Query |
createQuery(namespace, kind)
createQuery
(
namespace
:
string
,
kind
:
string
)
:
Query
;
Type | Name | Description |
---|---|---|
string
|
namespace | |
string
|
kind |
Type | Description |
---|---|
Query |
createQuery(namespace, kind)
createQuery
(
namespace
:
string
,
kind
:
string
[])
:
Query
;
Type | Name | Description |
---|---|---|
string
|
namespace | |
string[]
|
kind |
Type | Description |
---|---|
Query |
determineBaseUrl_(customApiEndpoint)
determineBaseUrl_
(
customApiEndpoint
?:
string
)
:
void
;
Determine the appropriate endpoint to use for API requests. If not explicitly defined, check for the "DATASTORE_EMULATOR_HOST" environment variable, used to connect to a local Datastore server.
Type | Name | Description |
---|---|---|
string
|
customApiEndpoint | Custom API endpoint. |
Type | Description |
---|---|
void |
double(value)
double
(
value
:
number
)
:
entity
.
Double
;
Type | Name | Description |
---|---|---|
number
|
value |
Type | Description |
---|---|
entity.Double |
double(value)
static
double
(
value
:
number
)
:
entity
.
Double
;
Helper function to get a Datastore Double object.
Type | Name | Description |
---|---|---|
number
|
value | The double value. |
Type | Description |
---|---|
entity.Double | {object} |
export(config)
export
(
config
:
ExportEntitiesConfig
)
:
Promise<LongRunningResponse>
;
Type | Name | Description |
---|---|---|
config |
Type | Description |
---|---|
Promise < LongRunningResponse > |
export(config, callback)
export
(
config
:
ExportEntitiesConfig
,
callback
:
LongRunningCallback
)
:
void
;
Type | Name | Description |
---|---|---|
config | ||
callback |
Type | Description |
---|---|
void |
geoPoint(coordinates)
geoPoint
(
coordinates
:
entity
.
Coordinates
)
:
entity
.
GeoPoint
;
Type | Name | Description |
---|---|---|
entity.Coordinates
|
coordinates |
Type | Description |
---|---|
entity.GeoPoint |
geoPoint(coordinates)
static
geoPoint
(
coordinates
:
entity
.
Coordinates
)
:
entity
.
GeoPoint
;
Helper function to get a Datastore Geo Point object.
Type | Name | Description |
---|---|---|
entity.Coordinates
|
coordinates | Coordinate value. |
Type | Description |
---|---|
entity.GeoPoint | {object} |
getIndexes(options)
getIndexes
(
options
?:
GetIndexesOptions
)
:
Promise<GetIndexesResponse>
;
Type | Name | Description |
---|---|---|
GetIndexesOptions
|
options |
Type | Description |
---|---|
Promise < GetIndexesResponse > |
getIndexes(options, callback)
getIndexes
(
options
:
GetIndexesOptions
,
callback
:
GetIndexesCallback
)
:
void
;
Type | Name | Description |
---|---|---|
GetIndexesOptions
|
options | |
GetIndexesCallback
|
callback |
Type | Description |
---|---|
void |
getIndexes(callback)
getIndexes
(
callback
:
GetIndexesCallback
)
:
void
;
Type | Name | Description |
---|---|---|
GetIndexesCallback
|
callback |
Type | Description |
---|---|
void |
getIndexesStream(options)
getIndexesStream
(
options
?:
GetIndexesOptions
)
:
NodeJS
.
ReadableStream
;
Get all of the indexes in this project as a readable object stream.
Type | Name | Description |
---|---|---|
GetIndexesOptions
|
options | Configuration object. See for a complete list of options. |
Type | Description |
---|---|
NodeJS.ReadableStream | {ReadableStream |
getProjectId()
getProjectId
()
:
Promise<string>
;
Type | Description |
---|---|
Promise <string> |
import(config)
import
(
config
:
ImportEntitiesConfig
)
:
Promise<LongRunningResponse>
;
Type | Name | Description |
---|---|---|
config |
Type | Description |
---|---|
Promise < LongRunningResponse > |
import(config, callback)
import
(
config
:
ImportEntitiesConfig
,
callback
:
LongRunningCallback
)
:
void
;
Type | Name | Description |
---|---|---|
config | ||
callback |
Type | Description |
---|---|
void |
index(id)
index
(
id
:
string
)
:
Index
;
Get a reference to an Index.
Type | Name | Description |
---|---|---|
string
|
id | The index name or id. |
Type | Description |
---|---|
Index | {Index} |
insert(entities)
insert
(
entities
:
Entities
)
:
Promise<InsertResponse>
;
Type | Name | Description |
---|---|---|
Entities
|
entities |
Type | Description |
---|---|
Promise < InsertResponse > |
insert(entities, callback)
insert
(
entities
:
Entities
,
callback
:
InsertCallback
)
:
void
;
Type | Name | Description |
---|---|---|
Entities
|
entities | |
InsertCallback
|
callback |
Type | Description |
---|---|
void |
int(value)
int
(
value
:
number
|
string
)
:
entity
.
Int
;
Type | Name | Description |
---|---|---|
number | string
|
value |
Type | Description |
---|---|
entity.Int |
int(value)
static
int
(
value
:
number
|
string
)
:
entity
.
Int
;
Helper function to get a Datastore Integer object.
This is also useful when using an ID outside the bounds of a JavaScript Number object.
Type | Name | Description |
---|---|---|
number | string
|
value | The integer value. |
Type | Description |
---|---|
entity.Int | {object} |
isDouble(value)
isDouble
(
value
?:
{})
:
boolean
;
Type | Name | Description |
---|---|---|
{}
|
value |
Type | Description |
---|---|
boolean |
isDouble(value)
static
isDouble
(
value
?:
{})
:
boolean
;
Helper function to check if something is a Datastore Double object.
Type | Name | Description |
---|---|---|
{}
|
value |
Type | Description |
---|---|
boolean | {boolean} |
isGeoPoint(value)
isGeoPoint
(
value
?:
{})
:
boolean
;
Type | Name | Description |
---|---|---|
{}
|
value |
Type | Description |
---|---|
boolean |
isGeoPoint(value)
static
isGeoPoint
(
value
?:
{})
:
boolean
;
Helper function to check if something is a Datastore Geo Point object.
Type | Name | Description |
---|---|---|
{}
|
value |
Type | Description |
---|---|
boolean | {boolean} |
isInt(value)
isInt
(
value
?:
{})
:
boolean
;
Type | Name | Description |
---|---|---|
{}
|
value |
Type | Description |
---|---|
boolean |
isInt(value)
static
isInt
(
value
?:
{})
:
boolean
;
Helper function to check if something is a Datastore Integer object.
Type | Name | Description |
---|---|---|
{}
|
value |
Type | Description |
---|---|
boolean | {boolean} |
isKey(value)
isKey
(
value
?:
{})
:
boolean
;
Type | Name | Description |
---|---|---|
{}
|
value |
Type | Description |
---|---|
boolean |
isKey(value)
static
isKey
(
value
?:
{})
:
boolean
;
Helper function to check if something is a Datastore Key object.
Type | Name | Description |
---|---|---|
{}
|
value |
Type | Description |
---|---|
boolean | {boolean} |
key(options)
key
(
options
:
entity
.
KeyOptions
)
:
entity
.
Key
;
Type | Name | Description |
---|---|---|
entity.KeyOptions
|
options |
Type | Description |
---|---|
entity.Key |
key(path)
key
(
path
:
PathType
[])
:
entity
.
Key
;
Type | Name | Description |
---|---|---|
PathType
[]
|
path |
Type | Description |
---|---|
entity.Key |
key(path)
key
(
path
:
string
)
:
entity
.
Key
;
Type | Name | Description |
---|---|---|
string
|
path |
Type | Description |
---|---|
entity.Key |
keyFromLegacyUrlsafe(key)
keyFromLegacyUrlsafe
(
key
:
string
)
:
entity
.
Key
;
Helper to convert URL safe key string to entity key object
This is intended to work with the "legacy" representation of a datastore "Key" used within Google App Engine (a so-called "Reference").
Type | Name | Description |
---|---|---|
string
|
key | Entity key object. |
Type | Description |
---|---|
entity.Key | {string} Created urlsafe key. |
keyToLegacyUrlSafe(key, locationPrefix)
keyToLegacyUrlSafe
(
key
:
entity
.
Key
,
locationPrefix
?:
string
)
:
Promise<string>
;
Type | Name | Description |
---|---|---|
entity.Key
|
key | |
string
|
locationPrefix |
Type | Description |
---|---|
Promise <string> |
keyToLegacyUrlSafe(key, callback)
keyToLegacyUrlSafe
(
key
:
entity
.
Key
,
callback
:
KeyToLegacyUrlSafeCallback
)
:
void
;
Type | Name | Description |
---|---|---|
entity.Key
|
key | |
callback |
Type | Description |
---|---|
void |
keyToLegacyUrlSafe(key, locationPrefix, callback)
keyToLegacyUrlSafe
(
key
:
entity
.
Key
,
locationPrefix
:
string
,
callback
:
KeyToLegacyUrlSafeCallback
)
:
void
;
Type | Name | Description |
---|---|---|
entity.Key
|
key | |
string
|
locationPrefix | |
callback |
Type | Description |
---|---|
void |
save(entities, gaxOptions)
save
(
entities
:
Entities
,
gaxOptions
?:
CallOptions
)
:
Promise<SaveResponse>
;
Type | Name | Description |
---|---|---|
Entities
|
entities | |
CallOptions
|
gaxOptions |
Type | Description |
---|---|
Promise < SaveResponse > |
save(entities, gaxOptions, callback)
save
(
entities
:
Entities
,
gaxOptions
:
CallOptions
,
callback
:
SaveCallback
)
:
void
;
Type | Name | Description |
---|---|---|
Entities
|
entities | |
CallOptions
|
gaxOptions | |
SaveCallback
|
callback |
Type | Description |
---|---|
void |
save(entities, callback)
save
(
entities
:
Entities
,
callback
:
SaveCallback
)
:
void
;
Type | Name | Description |
---|---|---|
Entities
|
entities | |
SaveCallback
|
callback |
Type | Description |
---|---|
void |
transaction(options)
transaction
(
options
?:
TransactionOptions
)
:
Transaction
;
Create a new Transaction object.
Type | Name | Description |
---|---|---|
options | Configuration object. |
Type | Description |
---|---|
Transaction | {Transaction} |
update(entities)
update
(
entities
:
Entities
)
:
Promise<UpdateResponse>
;
Type | Name | Description |
---|---|---|
Entities
|
entities |
Type | Description |
---|---|
Promise < UpdateResponse > |
update(entities, callback)
update
(
entities
:
Entities
,
callback
:
UpdateCallback
)
:
void
;
Type | Name | Description |
---|---|---|
Entities
|
entities | |
UpdateCallback
|
callback |
Type | Description |
---|---|
void |
upsert(entities)
upsert
(
entities
:
Entities
)
:
Promise<UpsertResponse>
;
Type | Name | Description |
---|---|---|
Entities
|
entities |
Type | Description |
---|---|
Promise < UpsertResponse > |
upsert(entities, callback)
upsert
(
entities
:
Entities
,
callback
:
UpsertCallback
)
:
void
;
Type | Name | Description |
---|---|---|
Entities
|
entities | |
UpsertCallback
|
callback |
Type | Description |
---|---|
void |