Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from radbrt/config_fix
Browse files Browse the repository at this point in the history
Config fix
  • Loading branch information
hholgersen authored Jan 19, 2023
2 parents 63744f4 + ac65ff8 commit 48ef49b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
1 change: 0 additions & 1 deletion meltano.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ plugins:
config:
start_date: '2010-01-01T00:00:00Z'
settings:
# TODO: To configure using Meltano, declare settings and their types here:
- name: username
- name: password
kind: password
Expand Down
9 changes: 8 additions & 1 deletion target_mssql/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_sqlalchemy_url(self, config: dict) -> str:

connection_url = sqlalchemy.engine.url.URL.create(
drivername="mssql+pymssql",
username=config["user"],
username=config["username"],
password=config["password"],
host=config["host"],
port=config["port"],
Expand Down Expand Up @@ -344,6 +344,10 @@ def to_sql_type(self, jsonschema_type: dict) -> sqlalchemy.types.TypeEngine: #
return cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.DATE())

maxlength = jsonschema_type.get("maxLength")
if maxlength is not None:
if maxlength > 8000:
return cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.TEXT())

return cast(
sqlalchemy.types.TypeEngine, sqlalchemy.types.VARCHAR(maxlength)
)
Expand Down Expand Up @@ -374,6 +378,9 @@ def create_temp_table_from_table(self, from_table_name):
f"{schema_name}.#{table_name}" if schema_name else f"#{table_name}"
)

droptable = f"DROP TABLE IF EXISTS {tmp_full_table_name}"
self.connection.execute(droptable)

ddl = f"""
SELECT TOP 0 *
into {tmp_full_table_name}
Expand Down
31 changes: 31 additions & 0 deletions target_mssql/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,37 @@ class Targetmssql(SQLTarget):
th.StringType,
description="SQLAlchemy connection string",
),
th.Property(
"username",
th.StringType,
description="SQL Server username",
),
th.Property(
"password",
th.StringType,
description="SQL Server password",
),
th.Property(
"host",
th.StringType,
description="SQL Server host",
),
th.Property(
"port",
th.StringType,
default="1433",
description="SQL Server port",
),
th.Property(
"database",
th.StringType,
description="SQL Server database",
),
th.Property(
"default_target_schema",
th.StringType,
description="Default target schema to write to",
),
).to_dict()

default_sink_class = mssqlSink
Expand Down
3 changes: 3 additions & 0 deletions target_mssql/tests/data_files/long_string.singer
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"type": "SCHEMA", "stream": "long_string", "schema": {"type": "object", "properties": { "CustomerID": {"type": "string", "maxlength": 12000}, "clientName": {"type": "string"} }}, "key_properties": ["CustomerID"]}
{"type": "RECORD", "stream": "long_string", "record": {"CustomerID": "1", "clientName": "Gitter Windows Desktop App"}}
{"type": "RECORD", "stream": "long_string", "record": {"CustomerID": "2", "clientName": "Gitter iOS App"}}
4 changes: 2 additions & 2 deletions target_mssql/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
@pytest.fixture()
def mssql_config():
return {
"sqlalchemy_url": "mssql+pymssql://sa:p@55w0rd@localhost:1433/master",
# "sqlalchemy_url": "mssql+pymssql://sa:p@55w0rd@localhost:1433/master",
"schema": "dbo",
"user": "sa",
"username": "sa",
"password": "P@55w0rd",
"host": "localhost",
"port": "1433",
Expand Down

0 comments on commit 48ef49b

Please sign in to comment.