Setup
Environment Variables
Hysteria ORM can be configured using environment variables or direct options. Example .env:
DB_TYPE=postgres
DB_HOST=localhost
DB_PORT=5432
DB_USER=root
DB_PASSWORD=root
DB_DATABASE=test
MONGO_URL=mongodb://root:root@localhost:27017
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=root
SQL Connection
import { SqlDataSource } from 'hysteria-orm';
// Using environment variables
const sql = new SqlDataSource();
await sql.connect();
// Or with explicit configuration
const sql = new SqlDataSource({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'root',
password: 'root',
database: 'test',
});
await sql.connect();
For detailed SQL connection options, see SQL ORM Introduction.
MongoDB Connection
import { MongoDataSource } from 'hysteria-orm';
// Using environment variable (MONGO_URL)
const mongo = new MongoDataSource();
await mongo.connect();
// Or with explicit configuration
const mongo = new MongoDataSource({
url: 'mongodb://root:root@localhost:27017',
});
await mongo.connect();
Redis Connection
import { redis } from 'hysteria-orm';
await redis.connect({
host: 'localhost',
port: 6379,
password: 'root',
});
Next: Environment