php - Save property type int google datastore

785

How can I define the property type, when I save a record into Google Datastore with PHP?

version should be type: Integer

color should be type: String

description should be type: Text (I want to save long text there)

created should be type: Date and time

and cardatas should be type Array or Text,

what is the best here for JSON datas?: Array or Text

 $datastore = new DatastoreClient();
    $key = 'protCarDatas';
    $time = date(DATE_RFC3339);
    $savedata = $datastore->entity(
        $key,
           [
             'version' => $version,
             'color' => $color,
             'description' => $desc,
             'created' => $time,
             'cardatas' => $fullCardDataJsonString
           ],
           ['excludeFromIndexes' => ['cardatas']]
    );

    $datastore->insert($savedata); 

Thanks for help!

869

Answer

Solution:

The types that Datastore supports are the following (from the Documentation):

  • Integers
  • Floating-point numbers
  • Strings
  • Dates
  • Binary data

So I would cast the variables to:

version: Integer

color: String

description: String

created: Date

cardatas: String

People are also looking for solutions to the problem: php - Undefined offset: 2 when I delete an element of the array and I want to return the rest of them

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.