clockworklabs / clockworklabs/SpacetimeDB

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

Open
#2,450 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect Timestamp formatting in the Rust, C# and TypeScript client SDKs, then review the SQL parser's Timestamp handling. Compare the existing RFC 3339 parsing with the proposed output approaches; done means equivalent client queries produce valid SQL that SpacetimeDB evaluates.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, rust, sql, typescript
Domain
api, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.