Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@techmmunity/symbiosis

techmmunity-symbiosis707Apache-2.00.0.31TypeScript support: included

Symbiosis - The Ultimate OM For All Databases

orm, odm, sql, nosql, dynamo, dynamodb, typeorm, typescript, database, data-mapper, object-mapper, techmmunity-symbiosis

readme

Techmmunity - Symbiosis

Style Guide: Techmmunity CodeFactor Coveralls Tests Npm Downloads

Symbiosis is an Object Mapper, an ORM + ODM, based on TypeORM syntax and ESLint plugable approach. Our intention here is standardize the connection and implementation of every database with the best performance possible, and for this, we use an plugable approach, so more people can contribute and create their on integration. This package alone can't do anything besides typing, the plugins do all the "dirt work".

Currently it only works with TypeScript (and transpiled JavaScript), and we plan to keep this way.

Discord Community Docs

Why use Techmmunity Symbiosis?

  • Easy to use and standardize. Regardless of the database, the implementation will be the same in all cases (except the most complex ones).
  • The plugable approach. With the community support, this OM can work with all the databases, be they NoSQL or SQL, as long as it has a plugin for it.
  • No globals! All that this package uses is encapsuled inside it's classes, so there is no need to worry about some config defined in a global scope compromising your code, but if you want, you can use setGlobalConnection() to allow globals.
  • Free and direct support. If you have any question, you can join our discord community, and we and the members of Techmmunity will help you!
  • Focused on microservices and serverless! We focus in keep it usable for serverless and microservices projects.

Install and Config

With Yarn:

yarn add @techmmunity/symbiosis reflect-metadata

With NPM:

npm i @techmmunity/symbiosis reflect-metadata

Configure tsconfig.json:

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "skipLibCheck": true
    }
}

Plugins List

All the Symbiosis Plugins have the techmmunity-symbiosis tag, so you can easily found all the plugins at this link.

Plugins List

Usage

Symbiosis only supports the Data Mapper pattern, so we can avoid mutability and bad code practices.

import { Column, Entity, PrimaryGeneratedColumn } from "@techmmunity/symbiosis";
// All plugins export a Connection class and a Repository type
import { Connection, Repository } from "example-symbiosis-plugin";

@Entity()
class FooEntity {
    @PrimaryColumn()
    public id: string;

    @Column()
    public foo: string;
}

type FooRepository = Repository<FooEntity>;

const bootstrap = async () => {
    const connection = new Connection({
        // Connection config here
        entities: [FooEntity],
    });

    await connection.load();
    await connection.connect();

    const fooRepository: FooRepository =
        connection.getRepository<FooEntity>(FooEntity);

    await fooRepository.save({
        bar: "foo",
    });

    await connection.close();
};

bootstrap();

Documentation

How to contribute?

All the details about contributing are in our website.

See here our to-dos.

Special Thanks

Contributors

This project exists thanks to all the people who contribute:

COMING SOON

Cool Kids

  • A very special thanks to the creators of TypeORM, without their code, this package would never exists.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased] - 0000-00-00

Added

Changed

Fixed

Removed

Dependencies

[0.0.31] - 2022-02-12

Added

Changed

  • [BC] Return of all repository methods.
    • Instead of returning directly the data, will return a object with a data property, so it can return more data

Fixed

Removed

Dependencies

[0.0.30] - 2021-12-25

Added

Changed

Fixed

Removed

  • All relational support

Dependencies

  • Update TypeScript to 4.5.4

[0.0.29] - 2021-12-05

Added

  • [BC] validate method to BaseConnection
    • Will be used to validate connection data
    • Ex: If mongodb plugin, validate if all entities have only one primary column, and it's name is _id
  • @OneToOne decorator
  • @OneToMany decorator
  • @ManyToOne decorator
  • [BC] Support for relations at save and insert methods
    • beforeSave and beforeInsert will now always return an data array, and a new prop returnArray to tell the devs of plugins / core if they should return an array to the final user or not
  • beforeInsert, beforeSave, beforeUpdate and beforeUpsert return formatted relations data in a new prop relations

Changed

  • [BC] save and insert doesn't need the extra type info anymore
    • .save<Array<Entity>>([data]) -> .save([data])
    • .save<Entity>(data) -> .save(data)
    • .insert<Array<Entity>>([data]) -> .insert([data])
    • .insert<Entity>(data) -> .insert(data)
  • [BC] Standardize upsert and update returns
    • Will now only return arrays
  • [BC] Update connect method to return this instead void
    • This way users can chain the methods
    • Ex: const connection = await new Connection().load().connect()
  • [Internal] Update options to completely remove entities and entitiesDir
  • Now loads both entities and entitiesDir options, so both can be used at the same time
  • [BC] Update extra metadata to allow infinite extra metadata
    • Now the extra metadata is one unique object, and it's properties are used to get the types
  • [Internal] after* And before* Methods Location
    • Will make it easier to use a unique function to convert data, and handle relations
  • Allow functions to be passed as strategy on PrimaryGeneratedColumn decorator

Fixed

  • metadataKey type of DefineEntityMetadataParams and GetEntityMetadataParams
  • [BC] before* and after* methods returns type of Repository class
  • Only validates if the plugin is installed on cli calls
    • The validation cold stay there, but in minified apps, it's impossible to validate if the plugin is installed, so it's better to only validate on CLI calls.

Removed

Dependencies

  • Bump @vercel/ncc from 0.31.1 to 0.33.0
  • Bump jest from 27.3.1 to 27.4.3
  • Bump lint-staged from 12.0.2 to 12.1.2
  • Bump @techmmunity/utils from 1.8.1 to 1.9.1
  • Bump prettier from 2.4.1 to 2.5.1
  • Bump eslint from 8.2.0 to 8.4.0
  • Bump @types/uuid from 8.3.1 to 8.3.3
  • Bump @types/jest from 27.0.2 to 27.0.3

[0.0.28] - 2021-11-16

Added

Changed

Fixed

  • Type FindConditions, now sub-entities also accept FindOperators.
  • [BC] getGlobalRepository return type
    • Now receives a Repository as type, instead an Entity
    • Ex: getGlobalRepository<Entity>(Entity) -> getGlobalRepository<EntityRepository>(Entity)

Removed

[0.0.27] - 2021-11-12

Added

  • SubEntity decorator
  • CountColumn decorator
  • EntityType type
  • runBeforeUpsert and runAfterUpsert types
  • [BC] close method to Connection

Changed

  • save database event is now insert
  • runBeforeSave -> runBeforeInsert
  • runAfterSave -> runAfterInsert
  • [BC] SaveDateColumn -> InsertDateColumn

Fixed

  • getGlobalConnection return type (add dynamic return type)
  • setGlobalConnection param type (add dynamic param type)

Removed

  • [BC] isSubEntity option from @Entity (replaced by @SubEntity())

[0.0.26] - 2021-11-04

Added

  • Tests to check if the entities of EntityManager are being loaded

Changed

  • Make entities of EntityManager public

Fixed

  • getGlobalRepository type
  • glob import type
  • loadEntities type (entitiesDir may be undefined)

Removed

[0.0.25] - 2021-10-26

Added

Changed

  • Change glob to tiny-glob because of problems with types

Removed

[0.0.21] - 2021-10-26

Added

  • enumName to ColumnMetadata

Changed

  • Update dependencies: eslint, lint-staged, @techmmunity/utils
  • Change properties accessibility of Connection:
    • protected options -> public options
    • protected entityManager -> public entityManager
    • protected logger -> public logger
  • Change properties accessibility of Repository:
    • protected tableName -> public tableName

Removed