Interacting with data
In order to continue, you must understand Mandarine Query Language (MQL), Models & Repositories
Main
Mandarine repositories work directly with MQL, since MQL serves as the primary query statement writer.
@CustomQuery decorator
The @CustomQuery
decorator allows you to write SQL queries in your repositories. While it is true that MQL & Mandarine's ORM aim to remove as much SQL & database code from your application's layer, it is also true that some use cases may require the use of complex SQL queries.
Syntax:
@CustomQuery(query: string, secure?: boolean)
query
: Query to executesecure
: whether the query has secured parameters such as $1, $2, ...Default: True
Usage
// usersModel.ts
import { Table, Id, GeneratedValue, Column } from "https://deno.land/x/mandarinets/mod.ts";
@Table({ schema: "public" })
class Users {
@Id()
@GeneratedValue({strategy: "SEQUENCE"})
@Column()
public id: number;
@Column()
public firstname: string;
@Column()
public lastname: string;
@Column()
public country: string;
constructor(firstname?: string, lastname?: string, country?: string) {
this.firstname = firstname;
this.lastname = lastname;
this.country = country;
}
}
Note
They keyword "await" should be used for all repository methods
Last updated
Was this helpful?