Skip to content

@breadstone/ziegel-data ​

MIT LicenseTypeScriptnpm

A robust abstraction layer for data access and entity management in the ziegel framework. Provides repository pattern, entity framework, reactive data access, and transaction management for enterprise applications.

Data Layer: Powerful data abstraction with repository pattern, entity framework, and RxJS-based reactivity for scalable TypeScript projects.

🚀 Overview ​

@breadstone/ziegel-data offers:

  • Repository Pattern: Generic repositories with query, reader, and writer abstractions
  • Entity Framework: Base classes for entities, identification, and converters
  • Unit of Work: Transaction management and change tracking
  • Repository Hub & Pool: Centralized management and pooling of repositories
  • Reactive Repositories: RxJS-based data access with change events
  • Context Resolution: Dependency injection for data contexts
  • Query System: Flexible queries with operators and sorting

📦 Installation ​

bash
npm install @breadstone/ziegel-data
# or
yarn add @breadstone/ziegel-data

🧩 Features & Usage Examples ​

Repository Pattern ​

typescript
import { IRepository, RepositoryBase } from '@breadstone/ziegel-data';

interface User { id: string; name: string; email: string; }
class UserRepository extends RepositoryBase<any, string, User&gt; implements IRepository<string, User&gt; {
  async getById(id: string) { return await this.findSingle(u => u.id === id); }
  async getAll() { return await this.findAll(); }
}

const userRepo = new UserRepository();
const user = await userRepo.getById('123');

Entity Framework ​

typescript
import { EntityBase } from '@breadstone/ziegel-data';
class User extends EntityBase<string&gt; {
  constructor(public name: string, public email: string, id?: string) {
    super(id || crypto.randomUUID());
  }
}

Unit of Work ​

typescript
import { UnitOfWork } from '@breadstone/ziegel-data';
class MyUoW extends UnitOfWork<any&gt; {
  users = new UserRepository();
}
const uow = new MyUoW();
await uow.users.add(new User('Max', 'max@example.com'));

Reactive Repositories ​

typescript
import { ReactiveRepositoryBase, IEntity } from '@breadstone/ziegel-data';
class RxUserRepo extends ReactiveRepositoryBase<any, string, User&gt; {}
const rxRepo = new RxUserRepo();
rxRepo.changes.subscribe(change => console.log(change));

📚 Package import points ​

typescript
import {
    // Context Resolution
    ContextResolver, IContextResolver,

    // Entity Conversion
    IEntityConverter,

    // Decorators
    Repository,

    // Entities
    EntityBase, IEntity,

    // Exceptions
    RepositoryException,

    // Identification
    IdentificatorBase, GuidIdentificator, IIdentificator,

    // Repositories
    RepositoryBase, IRepository, IRepositoryQuery,
    IRepositoryReader, IRepositoryWriter,

    // Repository Hub & Pool
    IRepositoryHub, RepositoryHub,
    IRepositoryPool, RepositoryPool, RepositoryPoolLocator,

    // Repository Query System
    RepositoryConditionOperator, RepositoryQueryOrderDirection,
    RepositoryResponse,

    // Reactive Repositories
    ReactiveRepositoryBase, IReactiveRepository, IReactiveRepositoryChanges,

    // Unit of Work
    IUnitOfWork, UnitOfWork
} from '@breadstone/ziegel-data';

Repository Hub & Pool ​

typescript
import { RepositoryHub, RepositoryPool } from '@breadstone/ziegel-data';
const hub = new RepositoryHub();
const pool = new RepositoryPool();
// Register and resolve repositories centrally

📚 API Documentation ​

For full details, see the generated API docs or browse the source code.

License ​

MIT

Issues ​

Please report bugs and feature requests in the Issue Tracker.


### From TypeORM
```typescript
// TypeORM
const users = await userRepository
  .createQueryBuilder("user")
  .where("user.active = :active", { active: true })
  .orderBy("user.name", "ASC")
  .skip(20)
  .take(10)
  .getMany();

// ziegel-data
const users = await userRepository.query()
  .where('active', QueryOperator.Equals, true)
  .orderBy('name', 'asc')
  .skip(20)
  .take(10)
  .toArray();

API Reference ​

For detailed API documentation, see the generated API reference.