latitude-dev / latitude

Developer-first embedded analytics
https://latitude.so
GNU Lesser General Public License v3.0
669 stars 26 forks source link

Fix: Properly handle object properties on Query Compiler #393

Closed csansoon closed 2 weeks ago

csansoon commented 3 weeks ago

Describe your changes

Compiler did not properly handle object properties. Before this commit, you could not:

Invoke object properties as methods

Some variable types can contain functions that may be useful in the query compilation run-time. A clear example is Dates, where a Date can be passed to a query as a param, and we may want to run date-related methods.

{minDate = param('start_date')}  -- Returns a Date object

SELECT *
FROM table
WHERE year >= {minDate.getYear()}   -- You can now run the .getYear() method from the date object!

Modify object properties as methods

You can now also modify the value from object properties such as arrays and hashes.

{ results = runQuery('other_query') }
{ results[0].name = 'foo' }  -- Modifying a property from an object

SELECT *
FROM table
WHERE name IN {#each results as row} {row.name} {/each}

Allow optional chaining operator (?.)

The optional chaining operator allows you to read the value of a property located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid.

{ results = runQuery('other_query') }

SELECT *
FROM table
WHERE name = {results[0]?.name ?? 'default'}  -- If there are no results, it will return 'default'

Checklist before requesting a review

changeset-bot[bot] commented 3 weeks ago

🦋 Changeset detected

Latest commit: 9a76c4883b4fec77bce3b85e9b43dc3e604aaed5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 15 packages | Name | Type | | ----------------------------------- | ----- | | @latitude-data/sql-compiler | Minor | | @latitude-data/server | Patch | | @latitude-data/base-connector | Patch | | @latitude-data/athena-connector | Patch | | @latitude-data/bigquery-connector | Patch | | @latitude-data/clickhouse-connector | Patch | | @latitude-data/databricks-connector | Patch | | @latitude-data/duckdb-connector | Patch | | @latitude-data/mssql-connector | Patch | | @latitude-data/mysql-connector | Patch | | @latitude-data/postgresql-connector | Patch | | @latitude-data/snowflake-connector | Patch | | @latitude-data/sqlite-connector | Patch | | @latitude-data/test-connector | Patch | | @latitude-data/trino-connector | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR