A powerful TypeScript Database Abstraction Layer (DBAL) that provides a unified interface for working with multiple database types including MySQL, PostgreSQL, MSSQL, and SQLite.
- 🔄 Multi-Database Support: Work with multiple databases using the same API
 - 🏗️ TypeScript First: Full TypeScript support with type safety and autocompletion
 - 🔨 Query Builder: Fluent interface for building complex SQL queries
 - 📊 Reporting & Analytics: Built-in support for aggregations, window functions, and complex data analysis
 - 🚀 Migrations: Version control for your database schema
 - 📦 Column Pack: Ready-to-use column definitions for common fields like usernames, emails, and timestamps
 - 🌱 Seeding: Populate your database with test data
 - 🔍 Schema Management: Track and manage your database schema
 - 💰 Transactions: Support for database transactions
 - 🛠️ DDL Operations: Create, alter, and drop database objects
 - ⚡ Database Functions: Built-in support for common database functions
 
Read the getting started guide.
npx riao db:create
npx riao migration:create create-users-table
import { Migration } from '@riao/dbal';
import { ColumnType } from '@riao/dbal';
import {
	BigIntKeyColumn,
	EmailColumn,
	UsernameColumn,
	PasswordColumn,
	CreateTimestampColumn,
	UpdateTimestampColumn,
} from '@riao/dbal/column-pack';
export default class Users extends Migration {
	override async up() {
		await this.ddl.createTable({
			name: 'users',
			ifNotExists: true,
			columns: [
				BigIntKeyColumn,
				UsernameColumn,
				EmailColumn,
				PasswordColumn,
				{
					name: 'balance',
					type: ColumnType.DECIMAL,
					significant: 15,
					decimal: 2,
					required: true,
					default: 10000.0,
				},
				CreateTimestampColumn,
				UpdateTimestampColumn,
			],
		});
	}
	override async down() {
		await this.ddl.dropTable({
			tables: 'users',
			ifExists: true,
		});
	}
}Run your migrations with
npx riao migration:run
src/users/user-repository.ts
import { maindb } from '../../database/main';
export interface User {
	id: number;
	username: string;
	email: string;
	password: string;
	balance: number;
	create_timestamp: Date;
	update_timestamp: Date;
}
export const users = maindb.getQueryRepository<User>({
	table: 'users'
});// Insert a record
await users.insertOne({
    username: 'John Doe',
    email: '[email protected]'
});
// Find records
const results = await users.find({
    where: {
        email: '[email protected]'
    }
});For detailed documentation, please read the docs!
We welcome contributions! Please see our Contributing Guidelines for details.
This project is licensed under the MIT License - see the LICENSE.md file for details.
If you encounter any issues or have questions, please open an issue on our GitHub repository.