External SQL Database
While actors can serve as a complete database solution, they can also complement your existing databases. For example, you might use actors to handle frequently-changing data that needs real-time access, while keeping less frequently accessed data in your traditional database.
Actors can be used with common SQL databases, such as PostgreSQL and MySQL.
Libraries
To facilitate interaction with SQL databases, you can use either ORM libraries or raw SQL drivers. Each has its own use cases and benefits:
-
ORM Libraries: Type-safe and easy way to interact with your database
-
Raw SQL Drivers: Direct access to the database for more flexibility
Hosting Providers
There are several options for places to host your SQL database:
Examples
Basic PostgreSQL Connection
Here's a basic example of a user actor that creates a database record on start and tracks request counts:
Using Drizzle ORM
Here's the same user actor pattern using Drizzle ORM for more type-safe database operations: