Skip to content

Commit e5f6cbd

Browse files
committed
drizzle / synapse
1 parent 4cd854e commit e5f6cbd

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

docs/home-automation/synapse/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ Synapse has 2 major components to install in order to achieve proper functionali
1818
1. Custom component: [synapse-extension](/docs/home-automation/synapse/extension)
1919
2. Typescript library: [install guide](/docs/home-automation/synapse/install)
2020

21+
## 🗄️ Database Support
22+
23+
Synapse uses [Drizzle ORM](https://orm.drizzle.team/) to support multiple database types:
24+
25+
- **SQLite** (default) - Local file-based storage
26+
- **PostgreSQL** - Production-ready relational database
27+
- **MySQL** - Alternative relational database
28+
29+
Database configuration is handled through environment variables or application configuration. See the [configuration section](/docs/home-automation/synapse/usage/advanced#database-configuration) for details.
30+
2131
## 👩‍🔧 Basic Usage
2232

2333
Creating a new entity is easy! You can even attach to events inline with

docs/home-automation/synapse/notes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ HOME_AUTOMATION.bootstrap({
4949

5050
- running BOTH setups at the same time may lead to undefined behavior
5151
- stop `prod` before starting `dev`
52-
- stored state in sqlite database is **NOT** automatically synced, and will match the machine
53-
- no critical information is stored in sqlite db, and it may be removed to "reset" at any time
52+
- stored state in database is **NOT** automatically synced, and will match the machine
53+
- no critical information is stored in the database, and it may be removed to "reset" at any time
5454

5555
## Sync not working
5656

@@ -60,7 +60,7 @@ The fix for this is to fully reset the app/integration.
6060
1. remove device ([🖼️](/img/synapse_delete.png))
6161
2. stop your application
6262
3. reboot home assistant
63-
4. *optional:* remove synapse db
63+
4. *optional:* remove synapse database
6464
5. start app and re-add to home assistant
6565

6666
## 🛠️ Managed Domains

docs/home-automation/synapse/syncing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ This document covers how `synapse` handles syncing state with Home Assistant, ma
99
## State Syncing
1010

1111
The `synapse` library operates off of a **push** model. When making changes to entity configuration / locals:
12-
1. written to local sqlite database
12+
1. written to local database (SQLite by default, or PostgreSQL/MySQL)
1313
2. if change should be reflect in ha (state / config update), immediately emit via websocket event
1414
3. receive by python `synapse-extension`, and reflect change in entity config
1515

16-
The sqlite database exists to track current state, it does not contain any historical information.
16+
The database exists to track current state, it does not contain any historical information.
1717
It's primary purpose to to restore state during application reboots (expected or otherwise), and it's data should reflect what is currently in memory by your app
1818

1919
> **Note**: removing entities from code will **NOT** clean up from database automatically

docs/home-automation/synapse/usage/advanced.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,40 @@ function MyService({ synapse, lifecycle }) {
9797
})
9898
}
9999
```
100+
101+
## 🗄️ Database Configuration
102+
103+
Synapse supports multiple database types through Drizzle ORM. Configure your database using environment variables or application configuration:
104+
105+
### Environment Variables
106+
107+
```bash
108+
# Database type (sqlite, postgresql, mysql)
109+
SYNAPSE_DATABASE_TYPE=postgresql
110+
111+
# Database connection URL
112+
SYNAPSE_DATABASE_URL=postgresql://user:password@localhost:5432/synapse
113+
```
114+
115+
### Application Configuration
116+
117+
```typescript
118+
HOME_AUTOMATION.bootstrap({
119+
configuration: {
120+
synapse: {
121+
DATABASE_TYPE: "postgresql",
122+
DATABASE_URL: "postgresql://user:password@localhost:5432/synapse"
123+
}
124+
},
125+
});
126+
```
127+
128+
### Database Types
129+
130+
| Type | Default URL | Description |
131+
|------|-------------|-------------|
132+
| `sqlite` | `file:./synapse_storage.db` | Local file-based storage |
133+
| `postgresql` | Custom | Production-ready relational database |
134+
| `mysql` | Custom | Alternative relational database |
135+
136+
> **Note**: For PostgreSQL and MySQL, you must provide a valid connection URL in the `DATABASE_URL` environment variable.

docs/home-automation/synapse/usage/locals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_position: 5
55
---
66

77
In addition to acting as entities for Home Assistant, `synapse` entities have the ability to store generic data locally.
8-
Data gets serialized and placed in the same sqlite database that maintains current state for your application.
8+
Data gets serialized and placed in the same database that maintains current state for your application.
99

1010
Updates to `locals` persist across boots of your application, and modifications do not trigger update events.
1111
The system operates the same way for all entity domains.

0 commit comments

Comments
 (0)