Skip to content

BeeORM is a lightweight, TypeScript-based Object-Relational Mapper (ORM) designed for simplicity and flexibility, I built it as a side project, inspired by Java's JPA.

License

Notifications You must be signed in to change notification settings

CoderAnchel/BeeORM

Repository files navigation

BeeORM Logo

A TypeScript ORM inspired by JPA – A Side Project for Learning

TypeScript NPM Version Package License NPM Downloads

📌 Description

BeeORM is a TypeScript-based ORM that I built as a side project, inspired by Java's JPA. One day, I thought it would be a great way to deepen my understanding of TypeScript by trying to create something similar.

This project is not meant to compete with or improve existing TypeScript ORMs—it's purely a learning experience. BeeORM uses decorators to define entities and properties, making database interactions more intuitive. It currently supports MySQL and focuses on entity registration, metadata handling, and query execution.

⚠️ Note: This project is not intended to replace or improve existing TypeScript ORMs. It’s purely a learning experience!

Key Features

  • 🏗 Decorator-based entity definitions:
    • Use decorators to define entities and their properties, making the code more readable and maintainable.
  • 🗄 Supports MySQL
    • BeeORM supports MySQL as the database backend, allowing you to perform CRUD operations seamlessly.
  • 🛠 Handles entity registration & metadata
    • Automatically registers entities and manages metadata, simplifying the setup process.
  • Executes queries in an intuitive way
    • Provides a straightforward API for executing queries, making database interactions easier.
  • 🏭 Repository for retrieving and pushing data
    • Similar to JPA and TypeORM, BeeORM includes a repository pattern for managing data access, providing methods for common operations like finding, saving, and deleting entities.

Similar to JPA and TypeORM, BeeORM includes a repository pattern for managing data access, providing methods for common operations like finding, saving, and deleting entities.

Entity Definitions

BeeORM uses decorators to define entities and their properties. Here is an example of how to define a User entity::

import { Entity, Column, PrimaryKey } from 'beeorm';

@Entity('user')
class User {
  @PrimaryKey('number')
  id!: number;

  @Column('string')
  name!: string;

  @Column('string')
  email!: string;
}
import { getRepository } from 'beeorm';
import { User } from './entities/user';

const userRepository = getRepository(User);

// Encontrar un usuario por ID
const user = await userRepository.findOne(1);

// Guardar un nuevo usuario
const newUser = new User();
newUser.name = 'John Doe';
newUser.email = '[email protected]';
await userRepository.save(newUser);

// Eliminar un usuario
await userRepository.delete(1);

When you define an entity, BeeORM creates the corresponding table for you. If you change a type, it will be updated. If you add a new attribute, it will create a new column. You can forget about all the configuration once you are done.

Installation

  1. Install the npm package:

    npm install typeorm --save

  2. You may need to install node typings:

    npm install @types/node --save-dev

TypeScript configuration

Also, make sure you are using TypeScript version 4.5 or higher, and you have enabled the following settings in tsconfig.json:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

You may also need to enable es6 in the lib section of compiler options, or install es6-shim from @types.

Quick Start

The quckiest way to start its dimple create a plain node project then

npm i beeorm

Create a file for beeorm initializer:

import { BeeORM } from "beeorm/main";
import {Product} from "./Entities/User";

async function initialize() {
    //Entities folder
    await BeeORM.init("./Entities");
    //DB connection
    await BeeORM.connection({
        host: "localhost",
        user: "root",
        password: "******",
        database: "xxxxxx"
    });
    //read your proyect decorators and magic happend
    await BeeORM.StartupQuery();
    //create repos
    const productRepo = await BeeORM.BeeFactory(Product);
}
initialize().catch(console.error);

This Entity will be represented has follows

import {Entity, Column} from "beeorm"
import {PrimaryKey} from "beeorm/primaryKey-decorator";

@Entity("Photo")
export class Photo {
    @PrimaryKey("id")
    @Column("number")
    id: number

    @Column("string")
    name: string

    @Column("string")
    description: string

    @Column("string")
    filename: string

    @Column("number")
    views: number

    @Column("boolean")
    isPublished: boolean
}

Running the application

Now if you run your index.ts, a connection with the database will be initialized and a database table for your photos will be created.

+-------------+--------------+----------------------------+
|                         photo                           |
+-------------+--------------+----------------------------+
| id          | int(11)      | PRIMARY KEY AUTO_INCREMENT |
| name        | varchar(100) |                            |
| description | text         |                            |
| filename    | varchar(255) |                            |
| views       | int(11)      |                            |
| isPublished | boolean      |                            |
+-------------+--------------+----------------------------+

Core Technologies

  • TypeScript
  • Node.js
  • MySQL

Dependencies

Getting Started

Note: BeeORM is a side project created for learning purposes. If there is enough interest, I will consider creating detailed documentation. For now, it serves as a fun and educational project.

Questions

For questions and support, please use the official GitHub Issues. The issue list of this repo is exclusively for bug reports and feature requests.

License

BeeORM is MIT licensed.

About

BeeORM is a lightweight, TypeScript-based Object-Relational Mapper (ORM) designed for simplicity and flexibility, I built it as a side project, inspired by Java's JPA.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published