@an5/adapters 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/python/table_client.py +9 -11
package/package.json
CHANGED
package/python/table_client.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import uuid
|
|
3
3
|
from typing import Dict, List, Optional
|
|
4
|
-
|
|
4
|
+
try:
|
|
5
|
+
from .base import DIALECT_MSSQL, DIALECT_POSTGRES, model_fields, _build_order_by, _parse_where, _quote, _quote_table, _resolve_table
|
|
6
|
+
except ImportError:
|
|
7
|
+
from base import DIALECT_MSSQL, DIALECT_POSTGRES, model_fields, _build_order_by, _parse_where, _quote, _quote_table, _resolve_table
|
|
5
8
|
|
|
6
9
|
# ─── Table Client ───────────────────────────────────────────────────────────────────
|
|
7
10
|
|
|
@@ -28,8 +31,8 @@ class AdapterTableClient:
|
|
|
28
31
|
return ""
|
|
29
32
|
if self._dialect == DIALECT_POSTGRES:
|
|
30
33
|
return f" LIMIT {take} OFFSET {skip}"
|
|
31
|
-
|
|
32
|
-
return f"{
|
|
34
|
+
order_prefix = "" if order_sql else " ORDER BY (SELECT NULL)"
|
|
35
|
+
return f"{order_prefix} OFFSET {skip} ROWS FETCH NEXT {take} ROWS ONLY"
|
|
33
36
|
|
|
34
37
|
def find_many(self, where=None, order_by=None, skip: int = 0, take: Optional[int] = None, select=None) -> List[Dict]:
|
|
35
38
|
params: Dict = {}
|
|
@@ -39,12 +42,9 @@ class AdapterTableClient:
|
|
|
39
42
|
query = f"SELECT * FROM {self._table_sql}{self._nolock}"
|
|
40
43
|
if where_sql:
|
|
41
44
|
query += f" WHERE {where_sql}"
|
|
42
|
-
if
|
|
43
|
-
query +=
|
|
44
|
-
|
|
45
|
-
if order_sql:
|
|
46
|
-
query += f" {order_sql}"
|
|
47
|
-
query += self._pagination(take, skip, order_sql)
|
|
45
|
+
if order_sql:
|
|
46
|
+
query += f" {order_sql}"
|
|
47
|
+
query += self._pagination(take, skip, order_sql)
|
|
48
48
|
return self._adapter.exec(query, list(params.values()))
|
|
49
49
|
|
|
50
50
|
def find_first(self, where=None, order_by=None, select=None) -> Optional[Dict]:
|
|
@@ -205,5 +205,3 @@ class AdapterTableClient:
|
|
|
205
205
|
|
|
206
206
|
scored.sort(key=lambda x: x[1])
|
|
207
207
|
return [{**row, "distance": dist} for row, dist in scored[:take]]
|
|
208
|
-
|
|
209
|
-
|