|
1 | 1 | # TypeORM-IRIS |
| 2 | + |
| 3 | +A TypeORM driver for InterSystems IRIS database, providing seamless integration between TypeORM and IRIS databases. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This driver enables you to use TypeORM with InterSystems IRIS databases, supporting both traditional SQL operations and IRIS-specific features. It includes connection pooling for high-performance applications. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install typeorm-iris |
| 13 | +``` |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +### Basic Connection |
| 18 | + |
| 19 | +```typescript |
| 20 | +import { IRISDataSource, IRISConnectionOptions } from "../src" |
| 21 | + |
| 22 | +const dataSourceOptions: IRISConnectionOptions = { |
| 23 | + name: "iris", |
| 24 | + type: "iris", |
| 25 | + host: "localhost", |
| 26 | + port: 1972, |
| 27 | + username: "_SYSTEM", |
| 28 | + password: "SYS", |
| 29 | + namespace: "USER", |
| 30 | + logging: true, |
| 31 | + dropSchema: true, |
| 32 | +} |
| 33 | + |
| 34 | +export function createDataSource(options: any): IRISDataSource { |
| 35 | + // @ts-ignore |
| 36 | + const dataSource = new IRISDataSource({ ...dataSourceOptions, ...options }) |
| 37 | + return dataSource |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +### Entity Definition |
| 42 | + |
| 43 | +```typescript |
| 44 | +import { Column, Entity } from "typeorm" |
| 45 | +import { PrimaryColumn } from "typeorm" |
| 46 | +import { Generated } from "typeorm" |
| 47 | + |
| 48 | +@Entity("sample01_post") |
| 49 | +export class Post { |
| 50 | + @PrimaryColumn() |
| 51 | + @Generated() |
| 52 | + id: number |
| 53 | + |
| 54 | + @Column() |
| 55 | + title: string |
| 56 | + |
| 57 | + @Column() |
| 58 | + text: string |
| 59 | + |
| 60 | + @Column({ nullable: false }) |
| 61 | + likesCount: number |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### Basic Operations |
| 66 | + |
| 67 | +```typescript |
| 68 | +import "reflect-metadata" |
| 69 | +import { Post } from "./entity/Post" |
| 70 | +import { createDataSource } from "../datasource" |
| 71 | + |
| 72 | +async function main() { |
| 73 | + const dataSource = createDataSource({ |
| 74 | + logging: true, |
| 75 | + synchronize: true, |
| 76 | + entities: [Post as any], |
| 77 | + }) |
| 78 | + |
| 79 | + try { |
| 80 | + await dataSource.initialize() |
| 81 | + } catch (error) { |
| 82 | + console.log("Cannot connect: ", error) |
| 83 | + return |
| 84 | + } |
| 85 | + |
| 86 | + const post = new Post() |
| 87 | + post.text = "Hello how are you?" |
| 88 | + post.title = "hello" |
| 89 | + post.likesCount = 100 |
| 90 | + |
| 91 | + const postRepository = dataSource.getRepository(Post) |
| 92 | + |
| 93 | + try { |
| 94 | + await postRepository.save(post) |
| 95 | + console.log("Post has been saved: ", post) |
| 96 | + } catch (error) { |
| 97 | + console.log("Cannot save. Error: ", error) |
| 98 | + } |
| 99 | + |
| 100 | + await dataSource.destroy() |
| 101 | +} |
| 102 | + |
| 103 | +void main() |
| 104 | +``` |
| 105 | + |
| 106 | +## Configuration Options |
| 107 | + |
| 108 | +```typescript |
| 109 | +interface IRISConnectionOptions { |
| 110 | + type: "iris" |
| 111 | + host?: string |
| 112 | + port?: number |
| 113 | + username?: string |
| 114 | + password?: string |
| 115 | + namespace?: string |
| 116 | + sharedmemory?: boolean // Default: false (required for 2025.2+) |
| 117 | + poolSize?: number // Default: 5 |
| 118 | + connectTimeout?: number // Default: 10 seconds |
| 119 | + entities?: EntitySchema[] // Entity definitions |
| 120 | + synchronize?: boolean // Auto-create tables |
| 121 | + logging?: boolean // Enable query logging |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +## Connection Pooling |
| 126 | + |
| 127 | +The driver includes built-in connection pooling to prevent memory leaks: |
| 128 | + |
| 129 | +```typescript |
| 130 | +import { IRISConnectionPool } from "typeorm-iris" |
| 131 | + |
| 132 | +const pool = new IRISConnectionPool( |
| 133 | + { |
| 134 | + host: "localhost", |
| 135 | + port: 1972, |
| 136 | + ns: "USER", |
| 137 | + user: "_SYSTEM", |
| 138 | + pwd: "SYS", |
| 139 | + sharedmemory: false, |
| 140 | + }, |
| 141 | + 5, |
| 142 | +) // Max 5 connections |
| 143 | + |
| 144 | +// Get connection from pool |
| 145 | +const connection = await pool.getConnection() |
| 146 | + |
| 147 | +try { |
| 148 | + // Use connection |
| 149 | + const iris = connection.createIris() |
| 150 | + // ... database operations |
| 151 | +} finally { |
| 152 | + // Always release connection back to pool |
| 153 | + pool.releaseConnection(connection) |
| 154 | +} |
| 155 | + |
| 156 | +// Clean shutdown |
| 157 | +await pool.closeAll() |
| 158 | +``` |
| 159 | + |
| 160 | +## Examples |
| 161 | + |
| 162 | +The repository includes several example files: |
| 163 | + |
| 164 | +- `sample/` - TypeORM entity examples |
| 165 | + |
| 166 | +## Supported Data Types |
| 167 | + |
| 168 | +The driver supports all standard SQL data types plus IRIS-specific types: |
| 169 | + |
| 170 | +| TypeORM Type | IRIS Type | Notes | |
| 171 | +| ------------------ | ---------- | ------------------------ | |
| 172 | +| `integer` | `INTEGER` | Auto-increment supported | |
| 173 | +| `varchar` | `VARCHAR` | Default length: 255 | |
| 174 | +| `text` | `TEXT` | Large text fields | |
| 175 | +| `datetime` | `DATETIME` | Timestamps | |
| 176 | +| `boolean` | `BIT` | True/false values | |
| 177 | +| `decimal` | `DECIMAL` | Precision and scale | |
| 178 | +| `uniqueidentifier` | `UUID` | GUID support | |
| 179 | + |
| 180 | +## Development |
| 181 | + |
| 182 | +### Building the Project |
| 183 | + |
| 184 | +```bash |
| 185 | +npm run build |
| 186 | +``` |
| 187 | + |
| 188 | +### Running Tests |
| 189 | + |
| 190 | +Start IRIS |
| 191 | + |
| 192 | +``` |
| 193 | +docker compose up -d iris |
| 194 | +``` |
| 195 | + |
| 196 | +```bash |
| 197 | +npm test |
| 198 | +``` |
| 199 | + |
| 200 | +Optionally tests can run with testcontainers, image needs to be passed as envionment variable |
| 201 | + |
| 202 | +```bash |
| 203 | +export IRIS_IMAGE=containers.intersystems.com/intersystems/iris-community:latest-preview |
| 204 | +``` |
| 205 | + |
| 206 | +### Type Checking |
| 207 | + |
| 208 | +```bash |
| 209 | +npm run typecheck |
| 210 | +``` |
| 211 | + |
| 212 | +### Running Examples |
| 213 | + |
| 214 | +```bash |
| 215 | +# Basic demo |
| 216 | +node build/compiled/sample1-simple-entity/app.js |
| 217 | + |
| 218 | +node build/compiled/sample2-one-to-one/app.js |
| 219 | + |
| 220 | +node build/compiled/sample3-many-to-one/app.js |
| 221 | + |
| 222 | +node build/compiled/sample4-many-to-many/app.js |
| 223 | + |
| 224 | +node build/compiled/sample16-indexes/app.js |
| 225 | + |
| 226 | +``` |
| 227 | + |
| 228 | +## Requirements |
| 229 | + |
| 230 | +- Node.js 20+ |
| 231 | +- InterSystems IRIS 2025.1+ |
| 232 | +- TypeORM 0.3+ |
| 233 | + |
| 234 | +## Contributing |
| 235 | + |
| 236 | +1. Fork the repository |
| 237 | +2. Create a feature branch |
| 238 | +3. Make your changes |
| 239 | +4. Add tests for new functionality |
| 240 | +5. Submit a pull request |
| 241 | + |
| 242 | +## License |
| 243 | + |
| 244 | +MIT License - see LICENSE file for details. |
| 245 | + |
| 246 | +## Support |
| 247 | + |
| 248 | +- [IRIS Documentation](https://docs.intersystems.com/) |
| 249 | +- [TypeORM Documentation](https://typeorm.io/) |
| 250 | +- [GitHub Issues](https://github.com/caretdev/typeorm-iris/issues) |
| 251 | + |
| 252 | +## Changelog |
| 253 | + |
| 254 | +### 0.1.0 |
| 255 | + |
| 256 | +- Initial release |
| 257 | +- Basic TypeORM driver implementation |
| 258 | +- Connection pooling support |
| 259 | +- Worker thread examples |
| 260 | +- Memory leak prevention |
0 commit comments