Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
How to work with Google Spanner Date type in Javascript?

I have multiple tables in Google Cloud Spanner with columns of type Date. Inserting entries with specified dates is not a problem, and reflects appropriately in the database. However, retrieving entries from the database into the Javascript frontend is where the issue lies. I can't seem to figure out in which format these date fields are.

My (Google Cloud Functions) code retrieves a customer from the database as follows:

async function fetch(database, query) {
  query.json = true;
  try {
    const [rows] = await database.run(query);
    return rows;
  } catch (error) {
    console.error("ERROR:", error);
    throw error;
  } finally {
    database.close();
  }
}

exports.fetchCustomer = functions.https.onCall(async (data, context) => {
  const database = instance.database(data.dataset);
  let address = fetch(database, {
    sql: `SELECT * FROM addresses WHERE addressId = '${data.id}'`,
  });
  let customer = fetch(database, {
    sql: `SELECT * FROM customers WHERE customerId = '${data.id}'`,
  });

  try {
    [address, customer] =
      await Promise.all([address, customer]);
    return [address[0], customer[0]];
  } catch (error) {
    console.error("ERROR:", error);
    throw error;
  }
});

On the front-end side, I have:

const fetchCustomer = httpsCallable(firebaseFunctions, 'fetchCustomer');
await fetchCustomer({dataset: this.dataset, id: this.customerId})
.then((res) => {
  this.address = res.data[0];
  this.customer = res.data[1];
}

The object this.customer then has a property dateOfBirth which seems to be an infinitely nested object, which I can't make sense of. How can I convert that property to a String with the format 'yyyy-mm-dd' or any other appropriate date format?

Any advice or information on the matter would be appreciated. Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This sample has an example (https://cloud.google.com/spanner/docs/samples/spanner-query-with-date-parameter#spanner_query_with_date_parameter-nodejs):

  rows.forEach(row => {
    const date = row[2]['value'];
    const json = row.toJSON();
    console.log(
      `VenueId: ${json.VenueId}, VenueName: ${json.VenueName},` +
        ` LastContactDate: ${JSON.stringify(date).substring(1, 11)}`
    );   }); 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda