Skip to content

Make printed output of Timestamp objects in all client SDK langs compatible with SQL queries #2450

@gefjon

Description

@gefjon

As in, it should be possible in a client to write:

ctx.subscription_builder()
  .subscribe(format!(
    "SELECT * FROM message WHERE sent >= {:?}",
    Timestamp::now(),
  ))
  .unwrap();

or the equivalent in C# or TypeScript, and wind up with a valid SQL query that SpacetimeDB will evaluate.

Currently, Timestamps print as raw us since the Unix epoch in Rust, and probably also in C#. I have no clue how printing objects works in TypeScript. OTOH, we parse them according to RFC 3339, which IIRC is roughly YYYY-MM-DDTHH:MM or whatever.

We have two obvious paths to unify this:

  1. Change Timestamp in Rust, C# and TypeScript to print as RFC 3339. In Rust, the time crate seems to do this. Presumably C# and TypeScript will also give us ways to make it happen with relatively little investment of engineer-hours. Note that we can almost certainly get away with unconditionally printing as UTC, or local time, or whatever's easiest, even if we're inconsistent between impls.
  2. Extend our SQL parser to accept a raw integer literal for Timestamps and treat it as a number of us since the Unix epoch. I am unsure how much effort this would be, as I don't know to what extent we control our SQL parser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions