Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • BaseModel

Index

Properties

createdAt

createdAt: number = 0

id

id: string = ""

updatedAt

updatedAt: number | null = null

Methods

delete

  • delete(): Promise<number>
  • Deletes the model from the database.

    Example

    await post.delete();
    

    Returns Promise<number>

hasMany

  • hasMany<T>(ctor: ObjectType<T>, foreignKey?: undefined | string, localKey?: undefined | string): QueryBuilder<T>
  • Type parameters

    Parameters

    • ctor: ObjectType<T>
    • Optional foreignKey: undefined | string
    • Optional localKey: undefined | string

    Returns QueryBuilder<T>

save

  • save(): Promise<void>
  • Persists the current changes to the database.

    Example

    const post = new Post();
    
    post.title = 'My Second Blog Post!';
    
    await post.save();
    

    Returns Promise<void>

Static all

  • Returns all models.

    Example

    const posts = await BlogPost.all();
    

    Type parameters

    Parameters

    Returns Promise<T[]>

Static create

  • Creates a new model with the given attributes. The Id will be automatically generated if none is provided.

    Example

    const post = await BlogPost.create({ title: 'My First Blog Post!' });
    

    Type parameters

    Parameters

    Returns Promise<T>

Static find

  • find<T>(this: ObjectType<T>, id: string): Promise<T | null>
  • Returns the model with the given id.

    Example

    const post = await BlogPost.find('5f5a41cc3eb990709eafda43');
    

    Type parameters

    Parameters

    Returns Promise<T | null>

Static findBy

  • findBy<T>(this: ObjectType<T>, key: string, value: any): Promise<T | null>
  • Returns the first model matching where the key matches value.

    Example

    const user = await User.findBy('email', 'john.smith@company.com');
    

    Type parameters

    Parameters

    Returns Promise<T | null>

Static limit

  • Limits the number of models returned.

    Type parameters

    Parameters

    Returns QueryBuilder<T>

Static orderBy

  • Specifies the order the models are returned.

    Example

    const posts = await BlogPost.orderBy('publishedAt', 'desc').get();
    

    Type parameters

    Parameters

    • this: ObjectType<T>
    • key: string
    • Default value order: "asc" | "desc" = "asc"

    Returns QueryBuilder<T>

Static where

  • Returns a QueryBuilder where key matches value.

    Example

    const posts = await BlogPost.where('status', 'published').get();
    

    Type parameters

    Parameters

    Returns QueryBuilder<T>

Static whereIn

  • Returns models where key is in the array of values.

    Example

    const comments = await Comment.whereIn('postId', [1, 2, 3]).get();
    

    Type parameters

    Parameters

    • this: ObjectType<T>
    • fieldName: string
    • values: any[]

    Returns QueryBuilder<T>

Legend

  • Constructor
  • Property
  • Method

Generated using TypeDoc