Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Expand All @@ -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)


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
157 changes: 82 additions & 75 deletions src/dataherald/resources/database_connections/database_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Mapping, cast
from typing import TYPE_CHECKING, Union

import httpx

Expand All @@ -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 (
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
),
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
),
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
),
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
),
Expand Down
41 changes: 35 additions & 6 deletions src/dataherald/types/database_connection_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading