Mandarine.TS
Latest
Latest
  • Mandarine.TS
  • Getting started
    • Installing Deno Runtime
    • Setting up Environment
    • Quick Example
  • Concepts
  • Mandarine Project Structure
  • Mandarine CLI
    • CLI Reference
      • mandarine new
      • mandarine generate
      • mandarine run
  • Mandarine Core
    • Core Initialization
    • Mandarine.json
    • Dot env file
    • Properties
      • The @Value Decorator
    • Components
      • Controller
      • Middleware
      • Repository
      • Component
      • Service
      • Configuration
      • Manual Component
    • Dependency Injection
      • Accessing DI container
    • Resource Handlers
      • Resource Handler Registry
      • Resource Handler
      • Resource Resolver
  • Mandarine MVC
    • Web MVC
    • Controllers
      • Routes
        • Parameterized Routes
      • HTTP Handlers
      • @ResponseStatus
    • Custom Middleware
    • Session Middleware
    • CORS Middleware
    • Template Engine
      • @Render Decorator
      • Accessing data from template
    • Launching web-app
    • Serving Static Content
    • Multipart Form Data
  • Mandarine Security
    • Sessions
  • Mandarine Data
    • ORM
      • Data source
      • Models
      • Repositories
        • Interacting with data
        • Updating data
    • Mandarine Query Language
  • Resources
    • Changelog
  • Plugins
    • Optional
    • Promise Repeater
Powered by GitBook
On this page
  • Main
  • Declaring a repository

Was this helpful?

  1. Mandarine Data
  2. ORM

Repositories

PreviousModelsNextInteracting with data

Last updated 4 years ago

Was this helpful?

Main

Along with Mandarine's built-in ORM framework, Mandarine offers you the ability to work with Repositories. As mentioned , 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 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);
} 

here
MandarineRepository