Getting Started
Welcome to FoundryORM! This guide will help you get up and running in minutes.
What is FoundryORM?
FoundryORM is an enterprise-grade Object-Relational Mapping library that provides a unified API for working with multiple databases. It supports PostgreSQL, MySQL, SQLite, and MongoDB, allowing you to switch between databases without changing your code.
Key Features
- Multi-Database Support: PostgreSQL, MySQL, SQLite, MongoDB
- TypeScript First: Full type safety with decorators
- Connection Pooling: Automatic connection management
- Transactions: Full transaction support with commit/rollback
- SQL Injection Protection: Parameterized queries
- Error Handling & Logging: Comprehensive error management
Prerequisites
Before you begin, ensure you have the following installed:
- Node.js 16.x or higher
- TypeScript 5.x or higher
- A supported database (PostgreSQL, MySQL, SQLite, or MongoDB)
Installation
Install FoundryORM using npm:
1npm install foundry-orm reflect-metadataOr using yarn:
1yarn add foundry-orm reflect-metadataTypeScript Configuration
Update your tsconfig.json to enable decorators:
tsconfig.json
1{
2 "compilerOptions": {
3 "target": "ES2020",
4 "module": "commonjs",
5 "experimentalDecorators": true,
6 "emitDecoratorMetadata": true,
7 "esModuleInterop": true
8 }
9}Quick Example
Here's a simple example to get you started:
app.ts
1import 'reflect-metadata';
2import { Connection, Entity, Column, BaseModel, ConsoleLogger } from 'foundry-orm';
3
4// Define your model
5@Entity('users')
6class User extends BaseModel {
7 @Column('id')
8 id!: number;
9
10 @Column('name')
11 name!: string;
12
13 @Column('email')
14 email!: string;
15
16 @Column('age')
17 age?: number;
18}
19
20// Connect to database
21const connection = new Connection(
22 'postgres',
23 {
24 host: 'localhost',
25 port: 5432,
26 database: 'mydb',
27 user: 'postgres',
28 password: 'password'
29 },
30 new ConsoleLogger()
31);
32
33await connection.connect();
34BaseModel.setConnection(connection);
35
36// Use it!
37const user = await User.create({
38 name: 'John Doe',
39 email: '[email protected]',
40 age: 30
41});
42
43console.log('Created user:', user);
44
45const allUsers = await User.findAll();
46console.log('All users:', allUsers);
47
48// Clean up
49await connection.disconnect();Next Steps
Now that you have FoundryORM installed, explore these topics:
- Installation Guide - Detailed installation instructions
- Quick Start - Complete tutorial
- Models & Decorators - Learn about defining models
- Database Connections - Configure your database
- Examples - See real-world examples
Need Help?
If you run into any issues, check out our GitHub Issues or join our community discussions.