{"id":16542631,"url":"https://github.com/tada5hi/typeorm-extension","last_synced_at":"2025-05-16T18:09:18.025Z","repository":{"id":37005280,"uuid":"378709842","full_name":"tada5hi/typeorm-extension","owner":"tada5hi","description":"This library provides utitlites to create \u0026 drop the database, seed the database and apply URL query parameter(s).","archived":false,"fork":false,"pushed_at":"2025-05-07T10:33:31.000Z","size":11815,"stargazers_count":241,"open_issues_count":15,"forks_count":38,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-05-15T02:43:40.235Z","etag":null,"topics":["better-sqlite3","database","instances","json","json-api","nodejs","orm","postgresql","seed","seeder","seeding","singleton","sqlite3","typeorm","typeorm-mysql","typescript"],"latest_commit_sha":null,"homepage":"https://typeorm-extension.tada5hi.net","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tada5hi.png","metadata":{"files":{"readme":"README.MD","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["tada5hi"]}},"created_at":"2021-06-20T18:04:10.000Z","updated_at":"2025-05-05T01:33:25.000Z","dependencies_parsed_at":"2023-02-14T02:01:09.649Z","dependency_job_id":"7dab6b9c-4e54-4cc4-865e-ee71e8598ee4","html_url":"https://github.com/tada5hi/typeorm-extension","commit_stats":{"total_commits":562,"total_committers":10,"mean_commits":56.2,"dds":0.4537366548042705,"last_synced_commit":"f498c4dd0027608cd3823754ddb087eb44fd1183"},"previous_names":[],"tags_count":85,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tada5hi%2Ftypeorm-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tada5hi%2Ftypeorm-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tada5hi%2Ftypeorm-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tada5hi%2Ftypeorm-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tada5hi","download_url":"https://codeload.github.com/tada5hi/typeorm-extension/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582907,"owners_count":22095518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["better-sqlite3","database","instances","json","json-api","nodejs","orm","postgresql","seed","seeder","seeding","singleton","sqlite3","typeorm","typeorm-mysql","typescript"],"created_at":"2024-10-11T18:58:09.574Z","updated_at":"2025-05-16T18:09:17.979Z","avatar_url":"https://github.com/tada5hi.png","language":"TypeScript","funding_links":["https://github.com/sponsors/tada5hi"],"categories":[],"sub_categories":[],"readme":"# Typeorm Extension 🚀\n\n[![npm version](https://badge.fury.io/js/typeorm-extension.svg)](https://badge.fury.io/js/typeorm-extension)\n[![codecov](https://codecov.io/gh/Tada5hi/typeorm-extension/branch/master/graph/badge.svg?token=4KNSG8L13V)](https://codecov.io/gh/Tada5hi/typeorm-extension)\n[![Master Workflow](https://github.com/Tada5hi/typeorm-extension/workflows/CI/badge.svg)](https://github.com/Tada5hi/typeorm-extension)\n[![Known Vulnerabilities](https://snyk.io/test/github/Tada5hi/typeorm-extension/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Tada5hi/typeorm-extension?targetFile=package.json)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits\u0026logoColor=white)](https://conventionalcommits.org)\n\nThis is a library to\n- `create`, `drop` \u0026 `seed` the (default-) database 🔥\n- manage one or many data-source instances 👻\n- parse \u0026 apply query parameters (extended **JSON:API** specification \u0026 fully typed) to:\n    - `filter` (related) resources according to one or more criteria,\n    - reduce (related) resource `fields`,\n    - `include` related resources,\n    - `sort` resources according to one or more criteria,\n    - limit the number of resources returned in a response by `page` limit \u0026 offset\n\n\u003e **Warning**\n\u003e This readme includes the documentation for the upcoming version 3.\n\u003e This is the [link](https://github.com/tada5hi/typeorm-extension/tree/v2) for the v2.\n\n**Table of Contents**\n- [Installation](#installation)\n- [Documentation](#documentation)\n- [Usage](#usage)\n  - [CLI](#cli)\n    - [Options](#cli-options)\n    - [Examples](#cli-examples)\n  - [Database](#database)\n    - [Create](#create)\n    - [Drop](#drop)\n  - [Instances](#instances)\n    - [Single](#single)\n    - [Multiple](#multiple)\n  - [Seeding](#seeding)\n    - [Configuration](#configuration)\n    - [Entity](#entity)\n    - [Factory](#factory)\n    - [Seed](#seed)\n    - [Execute](#execute)\n  - [Query](#query)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\n```bash\nnpm install typeorm-extension --save\n```\n\n## Documentation\n\nTo read the docs, visit [https://typeorm-extension.tada5hi.net](https://typeorm-extension.tada5hi.net)\n\n## Usage\n\n### CLI\n\nIf you use esm, the executable must be changed from `typeorm-extension` to `typeorm-extension-esm`.\nThe following commands are available in the terminal:\n- `typeorm-extension db:create` to create the database\n- `typeorm-extension db:drop` to drop the database\n- `typeorm-extension seed:run` seed the database\n- `typeorm-extension seed:create` to create a new seeder\n\nIf the application has not yet been built or is to be tested with ts-node, the commands can be adapted as follows:\n\n```\n\"scripts\": {\n    \"db:create\": \"ts-node ./node_modules/typeorm-extension/bin/cli.cjs db:create\",\n    \"db:drop\": \"ts-node ./node_modules/typeorm-extension/bin/cli.cjs db:drop\",\n    \"seed:run\": \"ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run\",\n    \"seed:create\": \"ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:create\"\n}\n```\nTo test the application in the context of an esm project, the following adjustments must be made:\n- executable `ts-node` to `ts-node-esm`\n- library path `cli.cjs` to `cli.mjs`\n\nRead the [Seeding Configuration](#configuration) section to find out how to specify the path,\nfor the seeder- \u0026 factory-location.\n\n#### CLI Options\n\n| Option                  | Commands                                           | Default         | Description                                                                                                                                                                                                                             |\n|-------------------------|----------------------------------------------------|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `--root` or `-r`        | `db:create`, `db:drop`, `seed:create` \u0026 `seed:run` | `process.cwd()` | Root directory of the project.                                                                                                                                                                                                          |\n| `--dataSource` or `-d`  | `db:create`, `db:drop` \u0026 `seed:run`                | `data-source`   | Name (or relative path incl. name) of the data-source file.                                                                                                                                                                             |\n| `--synchronize` or `-s` | `db:create`                            | `yes`           | Synchronize the database schema after database creation. Options: `yes` or `no`.                                                                                                                                                        |\n| `--initialDatabase`     | `db:create`                                        | `undefined`     | Specify the initial database to connect to. This option is only relevant for the `postgres` driver, which must always connect to a database. If no database is provided, the database name will be equal to the connection user name. |\n| `--name`                | `seed:create` \u0026 `seed:run`                         | `undefined`     | Name (or relative path incl. name) of the seeder.                                                                                                                                                                                       |\n| `--preserveFilePaths`   | `db:create`, `db:drop`, `seed:create` \u0026 `seed:run` | `false`         | This option indicates if file paths should be preserved and treated as if the just-in-time compilation environment is detected.                                                                                                         |\n\n#### CLI Examples\n**`Database Create`**\n```shell\nts-node ./node_modules/typeorm-extension/bin/cli.cjs db:create  -d src/data-source.ts\n```\n**`Database Drop`**\n```shell\nts-node ./node_modules/typeorm-extension/bin/cli.cjs db:drop  -d src/data-source.ts\n```\n\n**`Seed Run`**\n```shell\nts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run  -d src/data-source.ts\n```\n\n**`Seed Run Explicit`**\n```shell\nts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run  -d src/data-source.ts --name src/database/seeds/user.ts\n```\n\n**`Seed Create`**\n```shell\nts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:create  --name src/database/seeds/user.ts\n```\n\n### Database\nAn alternative to the CLI variant, is to `create` the database in the code base during the runtime of the application.\nTherefore, provide the `DataSourceOptions` for the DataSource manually, or let it be created automatically:\n\n#### Create\n**`Example #1`**\n```typescript\nimport { DataSource, DataSourceOptions } from 'typeorm';\nimport { createDatabase } from 'typeorm-extension';\n\n(async () =\u003e {\n    const options: DataSourceOptions = {\n        type: 'better-sqlite',\n        database: 'db.sqlite'\n    };\n\n    // Create the database with specification of the DataSource options\n    await createDatabase({\n        options\n    });\n\n    const dataSource = new DataSource(options);\n    await dataSource.initialize();\n    // do something with the DataSource\n})();\n```\n\n**`Example #2`**\n```typescript\nimport {\n    buildDataSourceOptions,\n    createDatabase\n} from 'typeorm-extension';\n\n(async () =\u003e {\n    const options = await buildDataSourceOptions();\n\n    // modify options\n\n    // Create the database with specification of the DataSource options\n    await createDatabase({\n        options\n    });\n\n    const dataSource = new DataSource(options);\n    await dataSource.initialize();\n    // do something with the DataSource\n})();\n```\n\n**`Example #3`**\n\nIt is also possible to let the library automatically search for the data-source under the hood.\nTherefore, it will search by default for a `data-source.{ts,js}` file in the following directories:\n- `{src,dist}/db/`\n- `{src,dist}/database`\n- `{src,dist}`\n\n```typescript\nimport { createDatabase } from 'typeorm-extension';\n\n(async () =\u003e {\n    // Create the database without specifying it manually\n    await createDatabase();\n})();\n```\n\n\nTo get a better overview and understanding of the\n[createDatabase](https://typeorm-extension.tada5hi.net/guide/database-api-reference.html#createdatabase)\nfunction, check out the documentation.\n\n#### Drop\n\n**`Example #1`**\n```typescript\nimport {\n    DataSource,\n    DataSourceOptions\n} from 'typeorm';\nimport { dropDatabase } from 'typeorm-extension';\n\n(async () =\u003e {\n    const options: DataSourceOptions = {\n        type: 'better-sqlite',\n        database: 'db.sqlite'\n    };\n\n    // Drop the database with specification of the DataSource options\n    await dropDatabase({\n        options\n    });\n})();\n```\n\n**`Example #2`**\n```typescript\nimport {\n    buildDataSourceOptions,\n    dropDatabase\n} from 'typeorm-extension';\n\n(async () =\u003e {\n    const options = await buildDataSourceOptions();\n\n    // modify options\n\n    // Drop the database with specification of the DataSource options\n    await dropDatabase({\n        options\n    });\n})();\n```\n\n**`Example #3`**\n\nIt is also possible to let the library automatically search for the data-source under the hood.\nTherefore, it will search by default for a `data-source.{ts,js}` file in the following directories:\n- `{src,dist}/db/`\n- `{src,dist}/database`\n- `{src,dist}`\n\n```typescript\nimport { dropDatabase } from 'typeorm-extension';\n\n(async () =\u003e {\n    // Drop the database without specifying it manually\n    await dropDatabase();\n})();\n```\n\nTo get a better overview and understanding of the\n[dropDatabase](https://typeorm-extension.tada5hi.net/guide/database-api-reference.html#dropDatabase)\nfunction, check out the documentation.\n\n### Instances\n\n#### Single\n\nThe default DataSource instance can be acquired, by not providing any alias at all or using the key `default`.\nIf no DataSource instance or DataSourceOptions object is deposited initially the method will attempt to locate and load\nthe DataSource file and initialize itself from there.\n\n```typescript\nimport { useDataSource } from 'typeorm-extension';\n\n(async () =\u003e {\n    const dataSource : DataSource = await useDataSource();\n})();\n```\n\nReference(s):\n- [setDataSource](https://typeorm-extension.tada5hi.net/guide/datasource-api-reference.html#setdatasource)\n- [useDataSource](https://typeorm-extension.tada5hi.net/guide/datasource-api-reference.html#usedatasource)\n\n#### Multiple\n\nIt is also possible to manage multiple DataSource instances.\nTherefore, each additional DataSource must be registered under a different alias.\nThis can be done by either setting the DataSource instance or the DataSourceOptions object for the given alias.\n\n```typescript\nimport { DataSource, DataSourceOptions } from 'typeorm';\nimport { setDataSource, useDataSource } from 'typeorm-extension';\n\n(async () =\u003e {\n    const secondDataSourceOptions : DataSourceOptions = {\n        // ...\n    };\n\n    const dataSource = new DataSource(secondDataSourceOptions);\n    setDataSource(dataSource, 'second');\n\n    const instance : DataSource = await useDataSource('second');\n})();\n```\n\nReference(s):\n- [setDataSource](https://typeorm-extension.tada5hi.net/guide/datasource-api-reference.html#setdatasource)\n- [setDataSourceOptions](https://typeorm-extension.tada5hi.net/guide/datasource-api-reference.html#setdatasourceoptions)\n\n### Seeding\n\nSeeding the database is fairly easy and can be achieved by following the steps below:\n- `Configuration`: Specify the seed and factory location by path or object.\n- `Entity`: Define one or more entities.\n- `Factory` (optional): Define a factory for each entity for which data should be automatically generated.\n- `Seed`: Define one or more seed classes to populate the database with an initial data set or generated data by a factory.\n- `Execute`: Run the seeder(s) with the CLI or in the code base.\n\n#### Configuration\n\nSeeder paths are configured as **glob patterns**, making it easy\nto match all the factory/seeder files in your project without configuration effort:\n- use `*` to match anything expect slashes and hidden files\n- use `**` to match zero or more directories\n- use comma separate values between `{}` to match against a list of options\n\nCheck out the [glob](https://www.npmjs.com/package/glob) documentation for other supported pattern features.\nIt is important to use the posix/unix path separator (/) because\nthe Windows path separator (\\\\) is used to match paths with literal global pattern characters.\n\nThe seeder- \u0026 factory-location, can be specified via:\n- `environment` variable(s)\n- extended `data-source.ts` file\n- `runSeeder(s)` method options parameter, in case of a direct code base usage\n\nThe following values are assumed by default:\n- factory path: `src/database/factories/**/*{.ts,.js}`\n- seed path: `src/database/seeds/**/*{.ts,.js}`\n\nNote: When seeder paths are configured as **glob patterns**, the paths are resolved and sorted in alphabetical order using filenames. This helps to ensure that the seeders are executed in the correct order.\n\nIt is possible to define that a seeder is only executed once.\nThis can either be set globally using the seedTacking option or locally using the track property of a seeder class.\n\n`data-source.ts`\n\n```typescript\nimport { DataSource, DataSourceOptions } from 'typeorm';\nimport { SeederOptions } from 'typeorm-extension';\n\nconst options: DataSourceOptions \u0026 SeederOptions = {\n    type: 'better-sqlite',\n    database: 'db.sqlite',\n\n    seeds: ['src/database/seeds/**/*{.ts,.js}'],\n    seedTracking: false,\n    factories: ['src/database/factories/**/*{.ts,.js}'],\n};\n\nexport const dataSource = new DataSource(options);\n```\n\n`runSeeder(s)`\n\n```typescript\nimport { DataSource, DataSourceOptions } from 'typeorm';\nimport { runSeeders, SeederOptions } from 'typeorm-extension';\n\n(async () =\u003e {\n    const options: DataSourceOptions = {\n        type: 'better-sqlite',\n        database: 'db.sqlite',\n    };\n\n    const dataSource = new DataSource(options);\n    await dataSource.initialize();\n\n    runSeeders(dataSource, {\n        seeds: ['src/database/seeds/**/*{.ts,.js}'],\n        factories: ['src/database/factories/**/*{.ts,.js}']\n    });\n})();\n```\n\n#### Entity\nTo get started, define one or more entities.\n\n**`user.ts`**\n```typescript\nimport {\n    Entity,\n    PrimaryGeneratedColumn,\n    Column\n} from 'typeorm';\n\n@Entity()\nexport class User {\n    @PrimaryGeneratedColumn()\n    id: number\n\n    @Column()\n    firstName: string\n\n    @Column()\n    lastName: string\n\n    @Column()\n    email: string\n}\n```\n\n#### Factory\nTo create entities with random data, create a factory for each desired entity.\nThe definition of a factory is **optional**.\n\nThe factory callback provides an instance of the [faker](https://fakerjs.dev/guide/) library as function argument,\nto populate the entity with random data.\n\n**`user.factory.ts`**\n```typescript\nimport { setSeederFactory } from 'typeorm-extension';\nimport { User } from './user';\n\nexport default setSeederFactory(User, (faker) =\u003e {\n    const user = new User();\n    user.firstName = faker.name.firstName('male');\n    user.lastName = faker.name.lastName('male');\n    user.email = faker.internet.email(user.firstName, user.lastName);\n\n    return user;\n})\n```\n\n#### Seed\nAnd last but not least, create a seeder. The seeder can be called by the cli command `seed` or in the codebase\nby using the function `runSeeder`.\nA seeder class only requires one method, called `run` and provides the arguments `dataSource` \u0026 `factoryManager`.\n\n**`user.seeder.ts`**\n\nA seeder class must implement the [Seeder](https://typeorm-extension.tada5hi.net/guide/seeding-api-reference.html) interface, and could look like this:\n\n```typescript\nimport { Seeder, SeederFactoryManager } from 'typeorm-extension';\nimport { DataSource } from 'typeorm';\nimport { User } from './user';\n\nexport default class UserSeeder implements Seeder {\n    /**\n     * Track seeder execution.\n     *\n     * Default: false\n     */\n    track = false;\n\n    public async run(\n        dataSource: DataSource,\n        factoryManager: SeederFactoryManager\n    ): Promise\u003cany\u003e {\n        const repository =  dataSource.getRepository(User);\n        await repository.insert([\n            {\n                firstName: 'Caleb',\n                lastName: 'Barrows',\n                email: 'caleb.barrows@gmail.com'\n            }\n        ]);\n\n        // ---------------------------------------------------\n\n        const userFactory = await factoryManager.get(User);\n        // save 1 factory generated entity, to the database\n        await userFactory.save();\n\n        // save 5 factory generated entities, to the database\n        await userFactory.saveMany(5);\n    }\n}\n```\n\n#### Execute\n\nPopulate the database from the code base:\n\n```typescript\nimport { DataSource, DataSourceOptions } from 'typeorm';\nimport { runSeeders, SeederOptions } from 'typeorm-extension';\nimport { User } from 'user';\n\n(async () =\u003e {\n    const options: DataSourceOptions \u0026 SeederOptions = {\n        type: 'better-sqlite',\n        database: 'db.sqlite',\n        entities: [User],\n\n        seeds: ['./*.seeder.ts'],\n        factories: ['./*.factory.ts']\n    };\n\n    const dataSource = new DataSource(options);\n    await dataSource.initialize();\n\n    await runSeeders(dataSource);\n})();\n```\n\nPopulate the database by explicit definitions from the codebase.\n\n```typescript\nimport { DataSource, DataSourceOptions } from 'typeorm';\nimport { runSeeders, SeederOptions } from 'typeorm-extension';\nimport { User } from 'user';\nimport UserSeeder from 'user.seeder';\nimport UserFactory from 'user.factory';\n\n(async () =\u003e {\n    const options: DataSourceOptions \u0026 SeederOptions = {\n        type: 'better-sqlite',\n        database: 'db.sqlite',\n        entities: [User],\n\n        seeds: [UserSeeder],\n        factories: [UserFactory]\n    };\n\n    const dataSource = new DataSource(options);\n    await dataSource.initialize();\n\n    await runSeeders(dataSource);\n})();\n```\n\n### Query\nThe query submodule enables query parameter (fields, filter, ...) values to be build, parsed \u0026 validated.\nTherefore, the [rapiq](https://www.npmjs.com/package/rapiq) library is used under the hood.\n\nThe query parameter options (allowed, default, ...) are fully typed 🔥 and depend on the (nested-) properties of the target entity passed to\nthe typeorm query builder.\n\nFor explanation proposes,\ntwo simple entities with a relation between them are declared to demonstrate the usage of the query utils:\n\n```typescript\nimport {\n    Entity,\n    PrimaryGeneratedColumn,\n    Column,\n    OneToOne,\n    JoinColumn\n} from 'typeorm';\n\n@Entity()\nexport class User {\n    @PrimaryGeneratedColumn({unsigned: true})\n    id: number;\n\n    @Column({type: 'varchar', length: 30})\n    @Index({unique: true})\n    name: string;\n\n    @Column({type: 'varchar', length: 255, default: null, nullable: true})\n    email: string;\n\n    @OneToOne(() =\u003e Profile)\n    profile: Profile;\n}\n\n@Entity()\nexport class Profile {\n    @PrimaryGeneratedColumn({unsigned: true})\n    id: number;\n\n    @Column({type: 'varchar', length: 255, default: null, nullable: true})\n    avatar: string;\n\n    @Column({type: 'varchar', length: 255, default: null, nullable: true})\n    cover: string;\n\n    @OneToOne(() =\u003e User)\n    @JoinColumn()\n    user: User;\n}\n```\n\nIn this example [routup](https://www.npmjs.com/package/routup) and the\nplugin [@routup/query](https://www.npmjs.com/package/@routup/query) is used to handle HTTP requests,\nbut there is also a guide available for [express](https://typeorm-extension.tada5hi.net/guide/query.html).\n\n```typescript\nimport { createServer } from 'node:http';\nimport type { Request, Response } from 'routup';\nimport { createNodeDispatcher, Router } from 'routup';\nimport { createHandler, useQuery } from '@routup/query';\n\nimport {\n    applyQuery,\n    useDataSource\n} from 'typeorm-extension';\n\nconst router = new Router();\nrouter.use(createHandler());\n\n/**\n * Get many users.\n *\n * Request example\n * - url: /users?page[limit]=10\u0026page[offset]=0\u0026include=profile\u0026filter[id]=1\u0026fields[user]=id,name\n *\n * Return Example:\n * {\n *     data: [\n *         {id: 1, name: 'tada5hi', profile: {avatar: 'avatar.jpg', cover: 'cover.jpg'}}\n *      ],\n *     meta: {\n *        total: 1,\n *        limit: 20,\n *        offset: 0\n *    }\n * }\n * @param req\n * @param res\n */\nrouter.get('users', async (req: Request, res: Response) =\u003e {\n    const dataSource = await useDataSource();\n    const repository = dataSource.getRepository(User);\n    const query = repository.createQueryBuilder('user');\n\n    // -----------------------------------------------------\n\n    const { pagination } = applyQuery(query, useQuery(req), {\n        defaultAlias: 'user',\n        fields: {\n            // porfile fields can only be included,\n            // if the relation 'profile' is included.\n            allowed: ['id', 'name', 'profile.id', 'profile.avatar'],\n        },\n        filters: {\n            // porfile.id can only be used as a filter,\n            // if the relation 'profile' is included.\n            allowed: ['id', 'name', 'profile.id'],\n        },\n        pagination: {\n            // only allow to select 20 items at maximum.\n            maxLimit: 20\n        },\n        relations: {\n            allowed: ['profile']\n        },\n        sort: {\n            // profile.id can only be used as sorting key,\n            // if the relation 'profile' is included.\n            allowed: ['id', 'name', 'profile.id']\n        },\n    });\n\n    // -----------------------------------------------------\n\n    const [entities, total] = await query.getManyAndCount();\n\n    return {\n        data: entities,\n        meta: {\n            total,\n            ...pagination\n        }\n    };\n});\n\nconst server = createServer(createNodeDispatcher(router));\nserver.listen(80);\n```\n\n## Contributing\n\nBefore starting to work on a pull request, it is important to review the guidelines for\n[contributing](./CONTRIBUTING.md) and the [code of conduct](./CODE_OF_CONDUCT.md).\nThese guidelines will help to ensure that contributions are made effectively and are accepted.\n\n## License\n\nMade with 💚\n\nPublished under [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftada5hi%2Ftypeorm-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftada5hi%2Ftypeorm-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftada5hi%2Ftypeorm-extension/lists"}