Skip to content

Commit 36c8ce6

Browse files
committed
Cleanup, update sample file
1 parent edd5515 commit 36c8ce6

16 files changed

Lines changed: 73 additions & 430 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ FROM mcr.microsoft.com/devcontainers/python:3.6-bullseye
33
ADD https://dl.yarnpkg.com/debian/pubkey.gpg /etc/apt/trusted.gpg.d/yarn.asc
44

55
RUN chmod +r /etc/apt/trusted.gpg.d/*.asc && \
6-
echo "deb http://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
6+
echo "deb http://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list

.pylintrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 23 deletions
This file was deleted.

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ pytest==7.0.1
66
pytest-mock==3.6.1
77
black==22.8.0
88
python-dotenv==0.20.0
9-
lz4==3.1.10
9+
lz4==3.1.10

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lz4==3.1.10
1+
lz4==3.1.10

samples.ipynb

Lines changed: 27 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": 1,
16+
"execution_count": 8,
1717
"metadata": {},
18-
"outputs": [
19-
{
20-
"name": "stdout",
21-
"output_type": "stream",
22-
"text": [
23-
"Loading SQLITECLOUD lib from: /Users/sam/projects/codermine/sqlitecloud-sdk/C/libsqcloud.so\n"
24-
]
25-
}
26-
],
18+
"outputs": [],
2719
"source": [
28-
"from sqlitecloud.conn_info import user,password,host,db_name,port\n",
29-
"from sqlitecloud.client import SqliteCloudClient, SqliteCloudAccount"
20+
"import sys\n",
21+
"\n",
22+
"sys.path.append('/workspaces/python/src')\n",
23+
"\n",
24+
"from sqlitecloud.conn_info import user, password, host, db_name, port\n",
25+
"from sqlitecloud.client import SqliteCloudClient\n",
26+
"from sqlitecloud.types import SqliteCloudAccount"
3027
]
3128
},
3229
{
@@ -40,27 +37,27 @@
4037
},
4138
{
4239
"cell_type": "code",
43-
"execution_count": 2,
40+
"execution_count": 9,
4441
"metadata": {},
4542
"outputs": [],
4643
"source": [
47-
"account = SqliteCloudAccount(user, password, host, db_name, port)\n",
44+
"account = SqliteCloudAccount(user, password, host, db_name, int(port))\n",
4845
"client = SqliteCloudClient(cloud_account=account)\n",
4946
"conn = client.open_connection()"
5047
]
5148
},
5249
{
5350
"cell_type": "code",
54-
"execution_count": 3,
51+
"execution_count": 10,
5552
"metadata": {},
5653
"outputs": [
5754
{
5855
"data": {
5956
"text/plain": [
60-
"'people'"
57+
"'chinook.sqlite'"
6158
]
6259
},
63-
"execution_count": 3,
60+
"execution_count": 10,
6461
"metadata": {},
6562
"output_type": "execute_result"
6663
}
@@ -78,17 +75,9 @@
7875
},
7976
{
8077
"cell_type": "code",
81-
"execution_count": 4,
78+
"execution_count": 15,
8279
"metadata": {},
83-
"outputs": [
84-
{
85-
"name": "stdout",
86-
"output_type": "stream",
87-
"text": [
88-
"select * from employees;\n"
89-
]
90-
}
91-
],
80+
"outputs": [],
9281
"source": [
9382
"query = \"select * from employees;\"\n",
9483
"result = client.exec_query(query, conn)"
@@ -103,21 +92,21 @@
10392
},
10493
{
10594
"cell_type": "code",
106-
"execution_count": 5,
95+
"execution_count": 16,
10796
"metadata": {},
10897
"outputs": [
10998
{
11099
"name": "stdout",
111100
"output_type": "stream",
112101
"text": [
113-
"{'emp_id': 1, 'emp_name': b'Bobby Tables'}\n",
114-
"{'emp_id': 1, 'emp_name': b'Bobby Tables'}\n",
115-
"{'emp_id': 1, 'emp_name': b'Bobby Tables'}\n",
116-
"{'emp_id': 1, 'emp_name': b'Bobby Tables'}\n",
117-
"{'emp_id': 1, 'emp_name': b'Bobby Tables'}\n",
118-
"{'emp_id': 1, 'emp_name': b'Bobby Tables'}\n",
119-
"{'emp_id': 1, 'emp_name': b'Bobby Tables'}\n",
120-
"{'emp_id': 1, 'emp_name': b'Bobby Tables'}\n"
102+
"{'EmployeeId': '1', 'LastName': 'Adams', 'FirstName': 'Andrew', 'Title': 'General Manager', 'ReportsTo': None, 'BirthDate': '1962-02-18 00:00:00', 'HireDate': '2002-08-14 00:00:00', 'Address': '11120 Jasper Ave NW', 'City': 'Edmonton', 'State': 'AB', 'Country': 'Canada', 'PostalCode': 'T5K 2N1', 'Phone': '+1 (780) 428-9482', 'Fax': '+1 (780) 428-3457', 'Email': 'andrew@chinookcorp.com'}\n",
103+
"{'EmployeeId': '2', 'LastName': 'Edwards', 'FirstName': 'Nancy', 'Title': 'Sales Manager', 'ReportsTo': '1', 'BirthDate': '1958-12-08 00:00:00', 'HireDate': '2002-05-01 00:00:00', 'Address': '825 8 Ave SW', 'City': 'Calgary', 'State': 'AB', 'Country': 'Canada', 'PostalCode': 'T2P 2T3', 'Phone': '+1 (403) 262-3443', 'Fax': '+1 (403) 262-3322', 'Email': 'nancy@chinookcorp.com'}\n",
104+
"{'EmployeeId': '3', 'LastName': 'Peacock', 'FirstName': 'Jane', 'Title': 'Sales Support Agent', 'ReportsTo': '2', 'BirthDate': '1973-08-29 00:00:00', 'HireDate': '2002-04-01 00:00:00', 'Address': '1111 6 Ave SW', 'City': 'Calgary', 'State': 'AB', 'Country': 'Canada', 'PostalCode': 'T2P 5M5', 'Phone': '+1 (403) 262-3443', 'Fax': '+1 (403) 262-6712', 'Email': 'jane@chinookcorp.com'}\n",
105+
"{'EmployeeId': '4', 'LastName': 'Park', 'FirstName': 'Margaret', 'Title': 'Sales Support Agent', 'ReportsTo': '2', 'BirthDate': '1947-09-19 00:00:00', 'HireDate': '2003-05-03 00:00:00', 'Address': '683 10 Street SW', 'City': 'Calgary', 'State': 'AB', 'Country': 'Canada', 'PostalCode': 'T2P 5G3', 'Phone': '+1 (403) 263-4423', 'Fax': '+1 (403) 263-4289', 'Email': 'margaret@chinookcorp.com'}\n",
106+
"{'EmployeeId': '5', 'LastName': 'Johnson', 'FirstName': 'Steve', 'Title': 'Sales Support Agent', 'ReportsTo': '2', 'BirthDate': '1965-03-03 00:00:00', 'HireDate': '2003-10-17 00:00:00', 'Address': '7727B 41 Ave', 'City': 'Calgary', 'State': 'AB', 'Country': 'Canada', 'PostalCode': 'T3B 1Y7', 'Phone': '1 (780) 836-9987', 'Fax': '1 (780) 836-9543', 'Email': 'steve@chinookcorp.com'}\n",
107+
"{'EmployeeId': '6', 'LastName': 'Mitchell', 'FirstName': 'Michael', 'Title': 'IT Manager', 'ReportsTo': '1', 'BirthDate': '1973-07-01 00:00:00', 'HireDate': '2003-10-17 00:00:00', 'Address': '5827 Bowness Road NW', 'City': 'Calgary', 'State': 'AB', 'Country': 'Canada', 'PostalCode': 'T3B 0C5', 'Phone': '+1 (403) 246-9887', 'Fax': '+1 (403) 246-9899', 'Email': 'michael@chinookcorp.com'}\n",
108+
"{'EmployeeId': '7', 'LastName': 'King', 'FirstName': 'Robert', 'Title': 'IT Staff', 'ReportsTo': '6', 'BirthDate': '1970-05-29 00:00:00', 'HireDate': '2004-01-02 00:00:00', 'Address': '590 Columbia Boulevard West', 'City': 'Lethbridge', 'State': 'AB', 'Country': 'Canada', 'PostalCode': 'T1K 5N8', 'Phone': '+1 (403) 456-9986', 'Fax': '+1 (403) 456-8485', 'Email': 'robert@chinookcorp.com'}\n",
109+
"{'EmployeeId': '8', 'LastName': 'Callahan', 'FirstName': 'Laura', 'Title': 'IT Staff', 'ReportsTo': '6', 'BirthDate': '1968-01-09 00:00:00', 'HireDate': '2004-03-04 00:00:00', 'Address': '923 7 ST NW', 'City': 'Lethbridge', 'State': 'AB', 'Country': 'Canada', 'PostalCode': 'T1H 1Y8', 'Phone': '+1 (403) 467-3351', 'Fax': '+1 (403) 467-8772', 'Email': 'laura@chinookcorp.com'}\n"
121110
]
122111
}
123112
],
@@ -135,41 +124,12 @@
135124
},
136125
{
137126
"cell_type": "code",
138-
"execution_count": 6,
127+
"execution_count": 17,
139128
"metadata": {},
140129
"outputs": [],
141130
"source": [
142131
"client.disconnect(conn)\n"
143132
]
144-
},
145-
{
146-
"cell_type": "markdown",
147-
"metadata": {},
148-
"source": [
149-
"You can bind values to parametric queries: you can pass parameters as positional values in an array"
150-
]
151-
},
152-
{
153-
"cell_type": "code",
154-
"execution_count": 7,
155-
"metadata": {},
156-
"outputs": [
157-
{
158-
"name": "stdout",
159-
"output_type": "stream",
160-
"text": [
161-
"ev type: <class 'int'>\n",
162-
"ev type: <class 'str'>\n"
163-
]
164-
}
165-
],
166-
"source": [
167-
"new_connection = client.open_connection()\n",
168-
"result = client.exec_statement(\"select * from employees where emp_id = ? and emp_name = ? \", [1,'Bobby Tables'],conn=new_connection)\n",
169-
"for r in result:\n",
170-
" print(r)\n",
171-
"client.disconnect(conn)"
172-
]
173133
}
174134
],
175135
"metadata": {
@@ -188,7 +148,7 @@
188148
"name": "python",
189149
"nbconvert_exporter": "python",
190150
"pygments_lexer": "ipython3",
191-
"version": "3.11.6"
151+
"version": "3.6.15"
192152
}
193153
},
194154
"nbformat": 4,

src/sqlitecloud/client.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" Module to interact with remote SqliteCloud database
22
33
"""
4-
from typing import Any, List, Optional
4+
from typing import Optional
55
from urllib import parse
66

77
from sqlitecloud.driver import Driver
@@ -37,8 +37,6 @@ def __init__(
3737

3838
self.config = SQCloudConfig()
3939

40-
# for pb in pub_subs:
41-
# self._pub_sub_cbs.append(("channel1", SQCloudPubSubCB(pb)))
4240
if connection_str:
4341
self.config = self._parse_connection_string(connection_str)
4442
elif cloud_account:
@@ -53,24 +51,16 @@ def open_connection(self) -> SQCloudConnect:
5351
SQCloudConnect: An instance of the SQCloudConnect class representing the connection to the SQCloud server.
5452
5553
Raises:
56-
Exception: If an error occurs while opening the connection.
54+
SQCloudException: If an error occurs while opening the connection.
5755
"""
5856
connection = self.driver.connect(
5957
self.config.account.hostname, self.config.account.port, self.config
6058
)
6159

62-
# SQCloudExec(connection, f"USE DATABASE {self.dbname};")
63-
64-
# for cb in self._pub_sub_cbs:
65-
# subscribe_pub_sub(connection, cb[0], cb[1])
66-
6760
return connection
6861

6962
def disconnect(self, conn: SQCloudConnect) -> None:
70-
"""Closes the connection to the database.
71-
72-
This method is used to close the connection to the database.
73-
"""
63+
"""Close the connection to the database."""
7464
self.driver.disconnect(conn)
7565

7666
def exec_query(
@@ -146,7 +136,7 @@ def _parse_connection_string(self, connection_string) -> SQCloudConfig:
146136
path = params.path
147137
database = path.strip("/")
148138
if database:
149-
config.account.database = database
139+
config.account.dbname = database
150140

151141
config.account.hostname = params.hostname
152142
config.account.port = (

src/sqlitecloud/driver.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import ssl
22
from typing import Optional, Union
33
import lz4.block
4-
from sqlitecloud.lz4_custom import lz4decode
54
from sqlitecloud.resultset import SQCloudResult
65
from sqlitecloud.types import (
76
SQCLOUD_CMD,
@@ -48,6 +47,9 @@ def connect(
4847
context.load_cert_chain(
4948
certfile=config.certificate, keyfile=config.certificate_key
5049
)
50+
if config.no_verify_certificate:
51+
context.check_hostname = False
52+
context.verify_mode = ssl.CERT_NONE
5153

5254
sock = context.wrap_socket(sock, server_hostname=hostname)
5355

@@ -103,10 +105,10 @@ def _internal_config_apply(
103105
command = "HASH" if config.account.password_hashed else "PASSWORD"
104106
buffer += f"AUTH USER {config.account.username} {command} {config.account.password};"
105107

106-
if config.account.database:
108+
if config.account.dbname:
107109
if config.create and not config.memory:
108-
buffer += f"CREATE DATABASE {config.account.database} IF NOT EXISTS;"
109-
buffer += f"USE DATABASE {config.account.database};"
110+
buffer += f"CREATE DATABASE {config.account.dbname} IF NOT EXISTS;"
111+
buffer += f"USE DATABASE {config.account.dbname};"
110112

111113
if config.compression:
112114
buffer += "SET CLIENT KEY COMPRESSION TO 1;"

src/sqlitecloud/pubsub.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/sqlitecloud/types.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,42 +56,39 @@ def __init__(self) -> None:
5656

5757

5858
class SqliteCloudAccount:
59-
def __init__(self):
59+
def __init__(
60+
self,
61+
username: Optional[str] = "",
62+
password: Optional[str] = "",
63+
hostname: Optional[str] = "",
64+
dbname: Optional[str] = "",
65+
port: Optional[int] = 8860,
66+
apikey: Optional[str] = "",
67+
) -> None:
6068
# User name is required unless connectionstring is provided
61-
self.username = ""
69+
self.username = username
6270
# Password is required unless connection string is provided
63-
self.password = ""
71+
self.password = password
6472
# Password is hashed
6573
self.password_hashed = False
6674
# API key instead of username and password
67-
self.apikey = ""
75+
self.apikey = apikey
6876
# Name of database to open
69-
self.database = ""
77+
self.dbname = dbname
7078
# Like mynode.sqlitecloud.io
71-
self.hostname = ""
72-
self.port = 8860
79+
self.hostname = hostname
80+
self.port = port
7381

7482

7583
class SQCloudConnect:
76-
def __init__(self):
77-
self.hostname: str = ""
78-
self.port: int = ""
84+
"""
85+
Represents the connection information.
86+
"""
7987

88+
def __init__(self):
8089
self.socket: any = None
81-
8290
self.config: SQCloudConfig
83-
8491
self.isblob: bool = False
85-
self.config_to_free: bool # todo: is this needed?
86-
87-
# pub/sub
88-
# todo: check uuid type
89-
self.uuid: str
90-
91-
# todo:
92-
# pubsubfd: int
93-
94-
# callback: SQCloudPubSubCB
9592

9693

9794
class SQCloudConfig:

0 commit comments

Comments
 (0)