Skip to content

Commit

Permalink
Release/1.0.2 (#172)
Browse files Browse the repository at this point in the history
* formating

* new api changes

* bump version number

* bump dependencies
  • Loading branch information
philkra authored Sep 25, 2023
1 parent 497977a commit 5f56ac3
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 178 deletions.
6 changes: 6 additions & 0 deletions codegen/api-rename-mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,11 @@
"template": "endpoint",
"name": "update_access_tokens"
}
},
"sql": {
"sqlQuery": {
"template": "sql_query",
"name": "query"
}
}
}
45 changes: 45 additions & 0 deletions codegen/templates/sql_query.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

def ${operation_id}(
self,
statement: str,
params: list = None,
consistency: str = "strong",
db_name: str = None,
branch_name: str = None,
) -> ApiResponse:
"""
${description}

Reference: ${docs_url}
Path: ${path}
Method: ${http_method}
Response status codes:
% for rc in params['response_codes']:
- ${rc["code"]}: ${rc["description"]}
% endfor
% if len(params['response_content_types']) > 1 :
Responses:
% for rc in params['response_content_types']:
- ${rc["content_type"]}
% endfor
% elif len(params['response_content_types']) == 1 :
Response: ${params['response_content_types'][0]["content_type"]}
% endif

:param statement: str The statement to run
:param params: dict The query parameters list. default: None
:param consistency: str The consistency level for this request. default: strong
:param db_name: str = None The name of the database to query. Default: database name from the client.
:param branch_name: str = None The name of the branch to query. Default: branch name from the client.

:returns ApiResponse
"""
db_branch_name = self.client.get_db_branch_name(db_name, branch_name)
url_path = f"/db/{db_branch_name}/sql"
headers = {"content-type": "application/json"}
payload = {
"statement": statement,
"params": params,
"consistency": consistency,
}
return self.request("POST", url_path, headers, payload)
303 changes: 152 additions & 151 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "xata"
version = "1.0.1"
version = "1.0.2"
description = "Python SDK for Xata.io"
authors = ["Xata <support@xata.io>"]
license = "Apache-2.0"
Expand Down
6 changes: 5 additions & 1 deletion tests/integration-tests/files_transormations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ def test_format_json_operations(self):
{"dpr": 2, "height": 200, "fit": "contain", "background": "pink", "format": "json"},
)
resp = json.load(io.BytesIO(resp))
assert resp == {'height': 400, 'original': {'file_size': 72786, 'format': 'image/png', 'height': 1646, 'width': 1504}, 'width': 365}
assert resp == {
"height": 400,
"original": {"file_size": 72786, "format": "image/png", "height": 1646, "width": 1504},
"width": 365,
}

def test_unknown_operations(self):
payload = {
Expand Down
45 changes: 26 additions & 19 deletions tests/integration-tests/type_json_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
# under the License.
#

import utils
import json

import utils
from faker import Faker

from xata.client import XataClient
Expand All @@ -31,34 +32,40 @@ def setup_class(self):
self.record_id = utils.get_random_string(24)
self.client = XataClient(db_name=self.db_name)

assert self.client.databases().create(self.db_name).is_success()
assert self.client.databases().create(self.db_name).is_success()

def teardown_class(self):
assert self.client.databases().delete(self.db_name).is_success()

def test_create_table_with_type(self):
assert self.client.table().create("Posts").is_success()
assert self.client.table().set_schema("Posts", {
"columns": [
{"name": "title", "type": "string"},
{"name": "meta", "type": "json"},
]
}).is_success()
assert (
self.client.table()
.set_schema(
"Posts",
{
"columns": [
{"name": "title", "type": "string"},
{"name": "meta", "type": "json"},
]
},
)
.is_success()
)

def test_insert_records(self):
result = self.client.records().bulk_insert("Posts", {"records": [
result = self.client.records().bulk_insert(
"Posts",
{
"title": self.fake.catch_phrase(),
"meta": json.dumps({
"number": it,
"nested": {
"random": it * it,
"a": "b"
"records": [
{
"title": self.fake.catch_phrase(),
"meta": json.dumps({"number": it, "nested": {"random": it * it, "a": "b"}}),
}
})
}
for it in range(25)
]})
for it in range(25)
]
},
)
assert result.is_success()

def test_query_records(self):
Expand Down
2 changes: 2 additions & 0 deletions xata/api/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get_clients(self) -> ApiResponse:
- 5XX: Unexpected Error
Response: application/json
:returns ApiResponse
"""
url_path = "/user/oauth/clients"
Expand Down Expand Up @@ -87,6 +88,7 @@ def get_access_tokens(self) -> ApiResponse:
- 5XX: Unexpected Error
Response: application/json
:returns ApiResponse
"""
url_path = "/user/oauth/tokens"
Expand Down
4 changes: 2 additions & 2 deletions xata/api/search_and_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,12 @@ def query(self, table_name: str, payload: dict = None, db_name: str = None, bran
returned is empty, but `page.meta.cursor` will include a cursor that can be
used to "tail" the table from the end waiting for new data to be inserted.
- `page.before=end`: This cursor returns the last page.
- `page.start=<cursor>`: Start at the beginning of the result set of the <cursor> query. This is equivalent to querying the
- `page.start=$cursor`: Start at the beginning of the result set of the $cursor query. This is equivalent to querying the
first page without a cursor but applying `filter` and `sort` . Yet the `page.start`
cursor can be convenient at times as user code does not need to remember the
filter, sort, columns or page size configuration. All these information are
read from the cursor.
- `page.end=<cursor>`: Move to the end of the result set of the <cursor> query. This is equivalent to querying the
- `page.end=$cursor`: Move to the end of the result set of the $cursor query. This is equivalent to querying the
last page with `page.before=end`, `filter`, and `sort` . Yet the
`page.end` cursor can be more convenient at times as user code does not
need to remember the filter, sort, columns or page size configuration. All
Expand Down
21 changes: 18 additions & 3 deletions xata/api/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
# under the License.
#

# ------------------------------------------------------- #
# Sql
# SQL service access
# Specification: workspace:v1.0
# ------------------------------------------------------- #

from xata.api_request import ApiRequest
from xata.api_response import ApiResponse

Expand All @@ -34,11 +40,20 @@ def query(
branch_name: str = None,
) -> ApiResponse:
"""
This endpoint performs the SQL query across the entire database branch. Set your SQL query in the parameter `query`.
Run an SQL query across the database branch.
Path: /db/{db_branch_name}/sql'
Reference: https://xata.io/docs/api-reference/db/db_branch_name/sql#sql-query
Path: /db/{db_branch_name}/sql
Method: POST
Response: application/json
Response status codes:
- 200: OK
- 201: OK
- 400: Bad Request
- 401: Authentication Error
- 404: Example response
- 503: ServiceUnavailable
- 5XX: Unexpected Error
- default: Unexpected Error
:param statement: str The statement to run
:param params: dict The query parameters list. default: None
Expand Down
2 changes: 1 addition & 1 deletion xata/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

# TODO this is a manual task, to keep in sync with pyproject.toml
# could/should be automated to keep in sync
__version__ = "1.0.1"
__version__ = "1.0.2"

PERSONAL_API_KEY_LOCATION = "~/.config/xata/key"
DEFAULT_DATA_PLANE_DOMAIN = "xata.sh"
Expand Down

0 comments on commit 5f56ac3

Please sign in to comment.