diff --git a/README.md b/README.md index d7c804d..c03892d 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,7 @@ client = Dataherald( environment="staging", ) -db_connection_response = client.database_connections.create( - db_connection_request_json="string", -) +db_connection_response = client.database_connections.create() print(db_connection_response.id) ``` @@ -60,9 +58,7 @@ client = AsyncDataherald( async def main() -> None: - db_connection_response = await client.database_connections.create( - db_connection_request_json="string", - ) + db_connection_response = await client.database_connections.create() print(db_connection_response.id) @@ -96,9 +92,7 @@ from dataherald import Dataherald client = Dataherald() try: - client.database_connections.create( - db_connection_request_json="string", - ) + client.database_connections.create() except dataherald.APIConnectionError as e: print("The server could not be reached") print(e.__cause__) # an underlying Exception, likely raised within httpx. @@ -141,9 +135,7 @@ client = Dataherald( ) # Or, configure per-request: -client.with_options(max_retries=5).database_connections.create( - db_connection_request_json="string", -) +client.with_options(max_retries=5).database_connections.create() ``` ### Timeouts @@ -166,9 +158,7 @@ client = Dataherald( ) # Override per-request: -client.with_options(timeout=5 * 1000).database_connections.create( - db_connection_request_json="string", -) +client.with_options(timeout=5 * 1000).database_connections.create() ``` On timeout, an `APITimeoutError` is thrown. @@ -207,9 +197,7 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to from dataherald import Dataherald client = Dataherald() -response = client.database_connections.with_raw_response.create( - db_connection_request_json="string", -) +response = client.database_connections.with_raw_response.create() print(response.headers.get('X-My-Header')) database_connection = response.parse() # get the object that `database_connections.create()` would have returned diff --git a/src/dataherald/resources/database_connections/database_connections.py b/src/dataherald/resources/database_connections/database_connections.py index 0ae301c..db2499a 100644 --- a/src/dataherald/resources/database_connections/database_connections.py +++ b/src/dataherald/resources/database_connections/database_connections.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Mapping, cast +from typing import TYPE_CHECKING, Union import httpx @@ -19,9 +19,8 @@ Query, Headers, NotGiven, - FileTypes, ) -from ..._utils import extract_files, maybe_transform, deepcopy_minimal +from ..._utils import maybe_transform from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper from ..._base_client import ( @@ -46,8 +45,13 @@ def __init__(self, client: Dataherald) -> None: def create( self, *, - db_connection_request_json: str, - file: FileTypes | NotGiven = NOT_GIVEN, + alias: str | NotGiven = NOT_GIVEN, + connection_uri: str | NotGiven = NOT_GIVEN, + credential_file_content: Union[object, str] | NotGiven = NOT_GIVEN, + llm_api_key: str | NotGiven = NOT_GIVEN, + metadata: object | NotGiven = NOT_GIVEN, + ssh_settings: database_connection_create_params.SshSettings | NotGiven = NOT_GIVEN, + use_ssh: bool | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -56,7 +60,7 @@ def create( timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> DBConnectionResponse: """ - Api Add Db Connection + Add Db Connection Args: extra_headers: Send extra headers @@ -67,23 +71,20 @@ def create( timeout: Override the client-level default timeout for this request, in seconds """ - body = deepcopy_minimal( - { - "db_connection_request_json": db_connection_request_json, - "file": file, - } - ) - files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) - if files: - # It should be noted that the actual Content-Type header that will be - # sent to the server will contain a `boundary` parameter, e.g. - # multipart/form-data; boundary=---abc-- - extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} - return self._post( "/api/database-connections", - body=maybe_transform(body, database_connection_create_params.DatabaseConnectionCreateParams), - files=files, + body=maybe_transform( + { + "alias": alias, + "connection_uri": connection_uri, + "credential_file_content": credential_file_content, + "llm_api_key": llm_api_key, + "metadata": metadata, + "ssh_settings": ssh_settings, + "use_ssh": use_ssh, + }, + database_connection_create_params.DatabaseConnectionCreateParams, + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -125,8 +126,13 @@ def update( self, id: str, *, - db_connection_request_json: str, - file: FileTypes | NotGiven = NOT_GIVEN, + alias: str | NotGiven = NOT_GIVEN, + connection_uri: str | NotGiven = NOT_GIVEN, + credential_file_content: Union[object, str] | NotGiven = NOT_GIVEN, + llm_api_key: str | NotGiven = NOT_GIVEN, + metadata: object | NotGiven = NOT_GIVEN, + ssh_settings: database_connection_update_params.SshSettings | NotGiven = NOT_GIVEN, + use_ssh: bool | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -135,7 +141,7 @@ def update( timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> DBConnectionResponse: """ - Api Update Db Connection + Update Db Connection Args: extra_headers: Send extra headers @@ -146,23 +152,20 @@ def update( timeout: Override the client-level default timeout for this request, in seconds """ - body = deepcopy_minimal( - { - "db_connection_request_json": db_connection_request_json, - "file": file, - } - ) - files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) - if files: - # It should be noted that the actual Content-Type header that will be - # sent to the server will contain a `boundary` parameter, e.g. - # multipart/form-data; boundary=---abc-- - extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} - return self._put( f"/api/database-connections/{id}", - body=maybe_transform(body, database_connection_update_params.DatabaseConnectionUpdateParams), - files=files, + body=maybe_transform( + { + "alias": alias, + "connection_uri": connection_uri, + "credential_file_content": credential_file_content, + "llm_api_key": llm_api_key, + "metadata": metadata, + "ssh_settings": ssh_settings, + "use_ssh": use_ssh, + }, + database_connection_update_params.DatabaseConnectionUpdateParams, + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -201,8 +204,13 @@ def __init__(self, client: AsyncDataherald) -> None: async def create( self, *, - db_connection_request_json: str, - file: FileTypes | NotGiven = NOT_GIVEN, + alias: str | NotGiven = NOT_GIVEN, + connection_uri: str | NotGiven = NOT_GIVEN, + credential_file_content: Union[object, str] | NotGiven = NOT_GIVEN, + llm_api_key: str | NotGiven = NOT_GIVEN, + metadata: object | NotGiven = NOT_GIVEN, + ssh_settings: database_connection_create_params.SshSettings | NotGiven = NOT_GIVEN, + use_ssh: bool | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -211,7 +219,7 @@ async def create( timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> DBConnectionResponse: """ - Api Add Db Connection + Add Db Connection Args: extra_headers: Send extra headers @@ -222,23 +230,20 @@ async def create( timeout: Override the client-level default timeout for this request, in seconds """ - body = deepcopy_minimal( - { - "db_connection_request_json": db_connection_request_json, - "file": file, - } - ) - files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) - if files: - # It should be noted that the actual Content-Type header that will be - # sent to the server will contain a `boundary` parameter, e.g. - # multipart/form-data; boundary=---abc-- - extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} - return await self._post( "/api/database-connections", - body=maybe_transform(body, database_connection_create_params.DatabaseConnectionCreateParams), - files=files, + body=maybe_transform( + { + "alias": alias, + "connection_uri": connection_uri, + "credential_file_content": credential_file_content, + "llm_api_key": llm_api_key, + "metadata": metadata, + "ssh_settings": ssh_settings, + "use_ssh": use_ssh, + }, + database_connection_create_params.DatabaseConnectionCreateParams, + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), @@ -280,8 +285,13 @@ async def update( self, id: str, *, - db_connection_request_json: str, - file: FileTypes | NotGiven = NOT_GIVEN, + alias: str | NotGiven = NOT_GIVEN, + connection_uri: str | NotGiven = NOT_GIVEN, + credential_file_content: Union[object, str] | NotGiven = NOT_GIVEN, + llm_api_key: str | NotGiven = NOT_GIVEN, + metadata: object | NotGiven = NOT_GIVEN, + ssh_settings: database_connection_update_params.SshSettings | NotGiven = NOT_GIVEN, + use_ssh: bool | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -290,7 +300,7 @@ async def update( timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> DBConnectionResponse: """ - Api Update Db Connection + Update Db Connection Args: extra_headers: Send extra headers @@ -301,23 +311,20 @@ async def update( timeout: Override the client-level default timeout for this request, in seconds """ - body = deepcopy_minimal( - { - "db_connection_request_json": db_connection_request_json, - "file": file, - } - ) - files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) - if files: - # It should be noted that the actual Content-Type header that will be - # sent to the server will contain a `boundary` parameter, e.g. - # multipart/form-data; boundary=---abc-- - extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} - return await self._put( f"/api/database-connections/{id}", - body=maybe_transform(body, database_connection_update_params.DatabaseConnectionUpdateParams), - files=files, + body=maybe_transform( + { + "alias": alias, + "connection_uri": connection_uri, + "credential_file_content": credential_file_content, + "llm_api_key": llm_api_key, + "metadata": metadata, + "ssh_settings": ssh_settings, + "use_ssh": use_ssh, + }, + database_connection_update_params.DatabaseConnectionUpdateParams, + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), diff --git a/src/dataherald/types/database_connection_create_params.py b/src/dataherald/types/database_connection_create_params.py index 6009150..c7698ca 100644 --- a/src/dataherald/types/database_connection_create_params.py +++ b/src/dataherald/types/database_connection_create_params.py @@ -2,14 +2,43 @@ from __future__ import annotations -from typing_extensions import Required, TypedDict +from typing import Union +from typing_extensions import TypedDict -from .._types import FileTypes - -__all__ = ["DatabaseConnectionCreateParams"] +__all__ = ["DatabaseConnectionCreateParams", "SshSettings"] class DatabaseConnectionCreateParams(TypedDict, total=False): - db_connection_request_json: Required[str] + alias: str + + connection_uri: str + + credential_file_content: Union[object, str] + + llm_api_key: str + + metadata: object + + ssh_settings: SshSettings + + use_ssh: bool + + +class SshSettings(TypedDict, total=False): + db_driver: str + + db_name: str + + host: str + + password: str + + private_key_password: str + + remote_db_name: str + + remote_db_password: str + + remote_host: str - file: FileTypes + username: str diff --git a/src/dataherald/types/database_connection_update_params.py b/src/dataherald/types/database_connection_update_params.py index da1ca27..db8a4c4 100644 --- a/src/dataherald/types/database_connection_update_params.py +++ b/src/dataherald/types/database_connection_update_params.py @@ -2,14 +2,43 @@ from __future__ import annotations -from typing_extensions import Required, TypedDict +from typing import Union +from typing_extensions import TypedDict -from .._types import FileTypes - -__all__ = ["DatabaseConnectionUpdateParams"] +__all__ = ["DatabaseConnectionUpdateParams", "SshSettings"] class DatabaseConnectionUpdateParams(TypedDict, total=False): - db_connection_request_json: Required[str] + alias: str + + connection_uri: str + + credential_file_content: Union[object, str] + + llm_api_key: str + + metadata: object + + ssh_settings: SshSettings + + use_ssh: bool + + +class SshSettings(TypedDict, total=False): + db_driver: str + + db_name: str + + host: str + + password: str + + private_key_password: str + + remote_db_name: str + + remote_db_password: str + + remote_host: str - file: FileTypes + username: str diff --git a/tests/api_resources/test_database_connections.py b/tests/api_resources/test_database_connections.py index 18bf09e..f737863 100644 --- a/tests/api_resources/test_database_connections.py +++ b/tests/api_resources/test_database_connections.py @@ -25,24 +25,35 @@ class TestDatabaseConnections: @parametrize def test_method_create(self, client: Dataherald) -> None: - database_connection = client.database_connections.create( - db_connection_request_json="string", - ) + database_connection = client.database_connections.create() assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @parametrize def test_method_create_with_all_params(self, client: Dataherald) -> None: database_connection = client.database_connections.create( - db_connection_request_json="string", - file=b"raw file contents", + alias="string", + connection_uri="string", + credential_file_content={}, + llm_api_key="string", + metadata={}, + ssh_settings={ + "db_name": "string", + "host": "string", + "username": "string", + "password": "string", + "remote_host": "string", + "remote_db_name": "string", + "remote_db_password": "string", + "private_key_password": "string", + "db_driver": "string", + }, + use_ssh=True, ) assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @parametrize def test_raw_response_create(self, client: Dataherald) -> None: - response = client.database_connections.with_raw_response.create( - db_connection_request_json="string", - ) + response = client.database_connections.with_raw_response.create() assert response.http_request.headers.get("X-Stainless-Lang") == "python" database_connection = response.parse() assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @@ -67,7 +78,6 @@ def test_raw_response_retrieve(self, client: Dataherald) -> None: def test_method_update(self, client: Dataherald) -> None: database_connection = client.database_connections.update( "string", - db_connection_request_json="string", ) assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @@ -75,8 +85,23 @@ def test_method_update(self, client: Dataherald) -> None: def test_method_update_with_all_params(self, client: Dataherald) -> None: database_connection = client.database_connections.update( "string", - db_connection_request_json="string", - file=b"raw file contents", + alias="string", + connection_uri="string", + credential_file_content={}, + llm_api_key="string", + metadata={}, + ssh_settings={ + "db_name": "string", + "host": "string", + "username": "string", + "password": "string", + "remote_host": "string", + "remote_db_name": "string", + "remote_db_password": "string", + "private_key_password": "string", + "db_driver": "string", + }, + use_ssh=True, ) assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @@ -84,7 +109,6 @@ def test_method_update_with_all_params(self, client: Dataherald) -> None: def test_raw_response_update(self, client: Dataherald) -> None: response = client.database_connections.with_raw_response.update( "string", - db_connection_request_json="string", ) assert response.http_request.headers.get("X-Stainless-Lang") == "python" database_connection = response.parse() @@ -110,24 +134,35 @@ class TestAsyncDatabaseConnections: @parametrize async def test_method_create(self, client: AsyncDataherald) -> None: - database_connection = await client.database_connections.create( - db_connection_request_json="string", - ) + database_connection = await client.database_connections.create() assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @parametrize async def test_method_create_with_all_params(self, client: AsyncDataherald) -> None: database_connection = await client.database_connections.create( - db_connection_request_json="string", - file=b"raw file contents", + alias="string", + connection_uri="string", + credential_file_content={}, + llm_api_key="string", + metadata={}, + ssh_settings={ + "db_name": "string", + "host": "string", + "username": "string", + "password": "string", + "remote_host": "string", + "remote_db_name": "string", + "remote_db_password": "string", + "private_key_password": "string", + "db_driver": "string", + }, + use_ssh=True, ) assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @parametrize async def test_raw_response_create(self, client: AsyncDataherald) -> None: - response = await client.database_connections.with_raw_response.create( - db_connection_request_json="string", - ) + response = await client.database_connections.with_raw_response.create() assert response.http_request.headers.get("X-Stainless-Lang") == "python" database_connection = response.parse() assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @@ -152,7 +187,6 @@ async def test_raw_response_retrieve(self, client: AsyncDataherald) -> None: async def test_method_update(self, client: AsyncDataherald) -> None: database_connection = await client.database_connections.update( "string", - db_connection_request_json="string", ) assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @@ -160,8 +194,23 @@ async def test_method_update(self, client: AsyncDataherald) -> None: async def test_method_update_with_all_params(self, client: AsyncDataherald) -> None: database_connection = await client.database_connections.update( "string", - db_connection_request_json="string", - file=b"raw file contents", + alias="string", + connection_uri="string", + credential_file_content={}, + llm_api_key="string", + metadata={}, + ssh_settings={ + "db_name": "string", + "host": "string", + "username": "string", + "password": "string", + "remote_host": "string", + "remote_db_name": "string", + "remote_db_password": "string", + "private_key_password": "string", + "db_driver": "string", + }, + use_ssh=True, ) assert_matches_type(DBConnectionResponse, database_connection, path=["response"]) @@ -169,7 +218,6 @@ async def test_method_update_with_all_params(self, client: AsyncDataherald) -> N async def test_raw_response_update(self, client: AsyncDataherald) -> None: response = await client.database_connections.with_raw_response.update( "string", - db_connection_request_json="string", ) assert response.http_request.headers.get("X-Stainless-Lang") == "python" database_connection = response.parse() diff --git a/tests/test_client.py b/tests/test_client.py index 970be3a..6513bef 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -672,7 +672,7 @@ def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> No with pytest.raises(APITimeoutError): self.client.post( "/api/database-connections", - body=dict(db_connection_request_json="string"), + body=dict(), cast_to=httpx.Response, options={"headers": {"X-Stainless-Streamed-Raw-Response": "true"}}, ) @@ -687,7 +687,7 @@ def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> Non with pytest.raises(APIStatusError): self.client.post( "/api/database-connections", - body=dict(db_connection_request_json="string"), + body=dict(), cast_to=httpx.Response, options={"headers": {"X-Stainless-Streamed-Raw-Response": "true"}}, ) @@ -1324,7 +1324,7 @@ async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) with pytest.raises(APITimeoutError): await self.client.post( "/api/database-connections", - body=dict(db_connection_request_json="string"), + body=dict(), cast_to=httpx.Response, options={"headers": {"X-Stainless-Streamed-Raw-Response": "true"}}, ) @@ -1339,7 +1339,7 @@ async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) with pytest.raises(APIStatusError): await self.client.post( "/api/database-connections", - body=dict(db_connection_request_json="string"), + body=dict(), cast_to=httpx.Response, options={"headers": {"X-Stainless-Streamed-Raw-Response": "true"}}, )