Skip to content

Commit

Permalink
feat: add connectors for using environment variables or fixed example…
Browse files Browse the repository at this point in the history
…s server
  • Loading branch information
dlovell authored and hussainsultan committed Aug 17, 2024
1 parent 145a7d7 commit 1503a85
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
9 changes: 2 additions & 7 deletions examples/local_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

import letsql as ls

pg = ls.postgres.connect(
# FIXME: use dyndns to point examples.letsql.com to the gcp sql host
host="34.135.241.141",
user="letsql",
password="letsql",
database="letsql",
)

pg = ls.postgres.connect_examples()
con = ls.connect() # empty connection
storage = ls.common.caching.ParquetCacheStorage(
source=con,
Expand Down
13 changes: 2 additions & 11 deletions examples/multi_engine.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import ibis

import letsql as ls


con = ls.connect() # empty connection

pg = ls.postgres.connect(
# FIXME: use dyndns to point examples.letsql.com to the gcp sql host
host="34.135.241.141",
user="letsql",
password="letsql",
database="letsql",
)
db = ibis.duckdb.connect()
pg = ls.postgres.connect_examples()
db = ls.duckdb.connect()


batting = pg.table("batting").pipe(con.register, table_name="batting")
Expand Down
17 changes: 17 additions & 0 deletions python/letsql/backends/postgres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@


class Backend(IbisPostgresBackend):
_top_level_methods = ("connect_examples", "connect_env")

@classmethod
def connect_env(cls, **kwargs):
from letsql.common.utils.postgres_utils import make_connection

return make_connection(**kwargs)

@classmethod
def connect_examples(cls):
return cls().connect(
host="examples.letsql.com",
user="letsql",
password="letsql",
database="letsql",
)

@staticmethod
def _register_and_transform_cache_tables(expr):
"""This function will sequentially execute any cache node that is not already cached"""
Expand Down
8 changes: 8 additions & 0 deletions python/letsql/backends/snowflake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@


class Backend(IbisSnowflakeBackend):
_top_level_methods = ("connect_env",)

@classmethod
def connect_env(cls, database="SNOWFLAKE_SAMPLE_DATA", schema="TPCH_SF1", **kwargs):
from letsql.common.utils.snowflake_utils import make_connection

return make_connection(database=database, schema=schema, **kwargs)

@staticmethod
def _register_and_transform_cache_tables(expr):
"""This function will sequentially execute any cache node that is not already cached"""
Expand Down

0 comments on commit 1503a85

Please sign in to comment.