Skip to content

Ability to add methods to Documents and Models #14

@harrim91

Description

@harrim91

Is your feature request related to a problem? Please describe.
We should be able to add methods to customise the behaviour models and documents.

Something like this...

interface UserProps {
  id: number;
  name: string;
}

interface UserMethods {
  sayHello: () => string;
}

interface UserStatics {
  count: () => number;
}

const schema = Joi.object(...);

const methods: UserMethods = {
  sayHello(): string {
    return `Hi, I'm ${this.name}`;
  }
};

const statics: UserStatics = {
  count(): number {
    const n = countTheItemsInTheTableSomehow()
    return n;
  }
};

const Users = new jedlik.Model<UserProps, UserStatics, UserMethods>({ table: 'users', schema, statics, methods });

Users.count(); // returns 0;

const user = User.create({ id: 1, name: 'Michael' });

await user.save()

Users.count(); // returns 1;

user.sayHello(); // returns 'Hi, I'm Michael'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions