🦉
Anacleto
GitHub
  • Anacleto
  • Getting started
    • Setup Anacleto
      • Setup local environmen
    • First tutorial
  • Anacleto Frontend
    • UI Builder
      • Components
        • DataTable
        • Form
          • Controls
            • Autocomplete
            • Button
            • CodeEditor
            • Dropdown
            • Image
            • InputText
            • Label
        • GridContainer
        • Splitter
        • Stack
        • TabView
        • Tree
    • Translation
    • Frontend script
      • Dialog and Toast
      • Window
  • Anacleto Backend
    • Backend script
      • googleBigQuery
      • googleDatastore
      • logger - console
      • mysql
      • Utils
  • Google cloud platform
    • Google
  • Anacleto developer
    • Work with us
      • Guidelines
    • Setup local enviroment
Powered by GitBook
On this page
  • getEntity
  • Syntax
  • Example
  • insertEntity
  • Syntax
  • Example
  • updateEntity
  • Syntax
  • Example
  • deleteEntity
  • Syntax
  • Example
  • list
  • Syntax
  • Example
  1. Anacleto Backend
  2. Backend script

googleDatastore

Utility class to interact with Google Datastore

All entities retrieved from datastore contain the __KEY__ property, an object from which to retrieve the entity key.

getEntity

Get a Google Datastore entity

Syntax

googleDatastore.getEntity({entityName, entityKey})
  • entityName datastore entity group name

  • entityKey entity key

  • returns a Promise.

Example

const entityName = "MASTER";
const entityKey =  "PIPPO"
}
const ret = googleDatastore.getEntity({entityName, entityKey)
    .then((res) => {
        //..
    })
    .catch((err) => {
        //..
    });

insertEntity

Insert a Google Datastore Entity

Syntax

googleDatastore.insertEntity({entityName,entity,entityAttributes})
  • entityName datastore entity group name

  • entity entity object

  • entityAttributes map attribute - type

  • return a Promise

Example

const insertPars = {
    entityName: "MASTER",
    entity: {
        "name": "PIPPO",
        "createDate": "2022-09-08 00:00:00"
    },
    entityAttributes: {
        name: { 
            type: "string",
            isPk: true 
        },
        createDate: { 
            type: "date"
        }
    }
}
const ret = googleDatastore.insertEntity(insertPars)
    .then((res) => {
        //Logiche per success true o false
    })
    .catch((err) => {
        //Logica per catch dell'errore
    });

updateEntity

Update a Google Datastore Entity.

Syntax

googleDatastore.updateEntity({entityName, entityKey, entityObj, entityAttributes, forceNullFields})
  • entityName datastore entity group name

  • entityKey entity key

  • entityObj object to save

  • entityAttributes map attribute - type

  • forceNullFields force not pass field to null

  • return a Promise

Example

const updatePars = {
    entityName: "MASTER",
    entityKey: "PIPPO",
    entityObj:{
        "name": "PIPPO",
        "createDate": "2022-09-08 00:00:00",
        "lastUpdate": "2022-09-15 00:00:00"
    },
    entityAttributes: {
        name: { 
            type: "string",
            isPk: true 
        },
        createDate: { 
            type: "date"
        },
        lastUpdate: { 
            type: "date"
        }
    },
    forceNullFields: false
};
const ret = googleDatastore.updateEntity(updatePars)
    .then((res) => {
        //Logiche per success true o false
    })
    .catch((err) => {
        //Logica per catch dell'errore
    });

deleteEntity

Delete a Google Datastore entity

Syntax

googleDatastore.deleteEntity({entityName, entityKey})
  • entityName datastore entity group name

  • entityKey entity to delete key

  • return a Promise

Example

const deletePars = {
    entityName: "MASTER",
    entityKey: "PIPPO"
}
const ret = googleDatastore.deleteEntity(deletePars)
    .then((res) => {
        //Logiche per success true o false
    })
    .catch((err) => {
        //Logica per catch dell'errore
    });

list

Return a list of entities

Syntax

googleDatastore.list
  • [select] fields to extract

  • entityName datastore entity group name

  • [filters] array of filter objects:

    • property property to filter

    • value filter value

    • [operator] filter operator, default =

  • [order] order object

    • property property to order

    • [descending] true: descending, false: ascending, default false

  • limit

  • [offset]

  • return a Promise

Example

//return first 10 entity
const pars = {
    "entityName": "MASTER",
    "limit": 10
}
const res = googleDatastore.list(pars)
    .then((res) => {
        //Logiche per success true o false
    })
    .catch((err) => {
        //Logica per catch dell'errore
    });

//return first 10 entity order by createDate desc
const pars = {
    "entityName": "MASTER",
    "limit": 10,
    "order": {
        "property": "createDate",
        "descending": true
    }
}
const res = googleDatastore.list(pars)
    .then((res) => {
        //Logiche per success true o false
    })
    .catch((err) => {
        //Logica per catch dell'errore
    });
PreviousgoogleBigQueryNextlogger - console

Last updated 2 years ago

In case the query searches only some fields or in case some sortings are necessary, it will be necessary to create indexes: if you are curious to understand how they work, check here: . If, you have already started using them and want to understand how to optimize them:

Indexes
Index optimization