Skip to content

Commit bf227c7

Browse files
committed
support unix_socket
1 parent c531e0c commit bf227c7

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/charm.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,20 @@ def _database_config(self):
9999
if None in [username, password, endpoints]:
100100
return {}
101101

102-
[host, port] = endpoints.split(":")
103-
104-
return {
102+
config = {
105103
"user": username,
106104
"password": password,
107-
"host": host,
108-
"port": port,
109105
"database": DATABASE_NAME,
110106
}
107+
if endpoints.startswith("file://"):
108+
config["unix_socket"] = endpoints[7:]
109+
config["port"] = "socket"
110+
else:
111+
host, port = endpoints.split(":")
112+
config["host"] = host
113+
config["port"] = port
114+
115+
return config
111116

112117
# ==============
113118
# Helpers
@@ -127,7 +132,7 @@ def _start_continuous_writes(self, starting_number: int) -> None:
127132
"src/continuous_writes.py",
128133
self._database_config["user"],
129134
self._database_config["password"],
130-
self._database_config["host"],
135+
self._database_config.get("host", self._database_config["unix_socket"]),
131136
self._database_config["port"],
132137
self._database_config["database"],
133138
CONTINUOUS_WRITE_TABLE_NAME,

src/continuous_writes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ def main():
5555
database_config = {
5656
"user": username,
5757
"password": password,
58-
"host": host,
59-
"port": port,
6058
"database": database,
6159
"use_pure": True,
6260
"connection_timeout": 5,
6361
}
62+
if port == "socket":
63+
database_config["unix_socket"] = host
64+
else:
65+
database_config["port"] = port
66+
database_config["host"] = host
6467

6568
continuous_writes(database_config, table_name, int(starting_number))
6669

0 commit comments

Comments
 (0)