Repositories

Main

Along with Mandarine's built-in ORM framework, Mandarine offers you the ability to work with Repositories. As mentioned here, repositories serve as a bridge between your database & your code, they execute tasks such as bringing information from the database to your code, deleting & saving, and more. In a nutshell, repositories allow you to execute queries programmatically, this means, you do not have to necessarily write the SQL query.

Declaring a repository

Repositories are declared by using the decorator @Repository() . The @Repository decorator targets an abstract class.

The abstract class that will represent your repository must be extended MandarineRepository . MandarineRepository is a generic class that will take T as your model's instance.

Syntax

@Repository()

Example

import { Repository, MandarineRepository, CustomQuery } from "https://deno.land/x/mandarinets/mod.ts";

@Repository()
abstract class MyRepository extends MandarineRepository<MyModel> {

    constructor() {
        super(MyModel);
    }
    
}

Note that all repositories must have a constructor with a super call. This super call will take your model's instance as shown above.

constructor() {
     super(MyModel);
} 

Last updated