Skip to content

Commit

Permalink
Allow for composite primary keys
Browse files Browse the repository at this point in the history
* [FIXED] Tables with composite primary keys are not quoted properly.
  • Loading branch information
doug-martin committed Apr 3, 2020
1 parent 182bd41 commit 6b80bea
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 168 deletions.
9 changes: 9 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# v0.7.5

* [FIXED] Tables with composite primary keys are not quoted properly.

# v0.7.4

* Fix code formatting
* Update root package.json with common dependencies

# v0.7.3

* [DOCS] Update docs to include a complete example of custom methods [#64](https://github.com/doug-martin/nestjs-query/issues/64)
Expand Down
2 changes: 1 addition & 1 deletion examples/nest-graphql-typeorm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ docker-compose up -d
From the root of the repo run the following commands.

```sh
npm install & npm run bootstrap && npm run build && npx lerna run migrate:up && npx lerna run seed
npm install & npm run bootstrap && npm run build && npx lerna run reset
```

In this directory `nestjs-query/examples/nest-graphql-typeorm`
Expand Down
2 changes: 1 addition & 1 deletion examples/nest-graphql-typeorm/e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SubTaskEntity } from '../src/sub-task/sub-task.entity';
import { TagEntity } from '../src/tag/tag.entity';
import { TodoItemEntity } from '../src/todo-item/todo-item.entity';

const tables = ['todo_item_entity', 'sub_task_entity', 'tag_entity'];
const tables = ['todo_item', 'sub_task', 'tag'];
export const truncate = async (connection: Connection): Promise<void> => {
await tables.reduce(async (prev, table) => {
await prev;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

47 changes: 0 additions & 47 deletions examples/nest-graphql-typeorm/migrations/1582247882223-add-tags.ts

This file was deleted.

6 changes: 3 additions & 3 deletions examples/nest-graphql-typeorm/ormconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"username": "graphqltypeorm",
"database": "graphql_typeorm",
"autoLoadEntities": true,
"migrations": ["dist/migrations/**.js"],
"seeds": ["./seeds.ts"],
"synchronize": false,
"entities": ["**/*.entity.js"],
"seeds": ["./dist/seeds.js"],
"synchronize": true,
"logging": true,
"cli": {
"migrationsDir": "./migrations"
Expand Down
7 changes: 3 additions & 4 deletions examples/nest-graphql-typeorm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "APP_ROOT_PATH=. nest start --watch",
"start:prod": "node dist/main",
"reset": "typeorm schema:drop && npm run migrate:up && npm run seed",
"migrate:up": "typeorm migration:run",
"migrate:generate": "npm run build && typeorm migration:generate -d ./migrations ",
"seed": "ts-node ../../node_modules/typeorm-seeding/dist/cli.js --config ./ormconfig.json seed"
"reset": "npm run build && typeorm schema:drop && npm run schema:sync && npm run seed",
"schema:sync": "typeorm schema:sync",
"seed": "../../node_modules/typeorm-seeding/dist/cli.js --config ./ormconfig.json seed"
},
"dependencies": {
"@nestjs-query/core": "^0.7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ObjectType, ID, GraphQLISODateTime } from '@nestjs/graphql';
@ObjectType('SubTask')
export class SubTaskDTO {
@FilterableField(() => ID)
id!: string;
id!: number;

@FilterableField()
title!: string;
Expand Down
8 changes: 4 additions & 4 deletions examples/nest-graphql-typeorm/src/sub-task/sub-task.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
} from 'typeorm';
import { TodoItemEntity } from '../todo-item/todo-item.entity';

@Entity()
@Entity({ name: 'sub_task' })
export class SubTaskEntity {
@PrimaryGeneratedColumn()
id!: string;
id!: number;

@Column()
title!: string;
Expand All @@ -24,14 +24,14 @@ export class SubTaskEntity {
@Column()
completed!: boolean;

@Column({ nullable: false })
@Column({ nullable: false, name: 'todo_item_id' })
todoItemId!: string;

@ManyToOne((): ObjectType<TodoItemEntity> => TodoItemEntity, (td) => td.subTasks, {
onDelete: 'CASCADE',
nullable: false,
})
@JoinColumn()
@JoinColumn({ name: 'todo_item_id' })
todoItem!: TodoItemEntity;

@CreateDateColumn()
Expand Down
2 changes: 1 addition & 1 deletion examples/nest-graphql-typeorm/src/tag/dto/tag.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ObjectType, ID, GraphQLISODateTime } from '@nestjs/graphql';
@ObjectType('Tag')
export class TagDTO {
@FilterableField(() => ID)
id!: string;
id!: number;

@FilterableField()
name!: string;
Expand Down
4 changes: 2 additions & 2 deletions examples/nest-graphql-typeorm/src/tag/tag.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
} from 'typeorm';
import { TodoItemEntity } from '../todo-item/todo-item.entity';

@Entity()
@Entity({ name: 'tag' })
export class TagEntity {
@PrimaryGeneratedColumn()
id!: string;
id!: number;

@Column()
name!: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ObjectType, ID, GraphQLISODateTime, Field } from '@nestjs/graphql';
@ObjectType('TodoItem')
export class TodoItemDTO {
@FilterableField(() => ID)
id!: string;
id!: number;

@FilterableField()
title!: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
import { SubTaskEntity } from '../sub-task/sub-task.entity';
import { TagEntity } from '../tag/tag.entity';

@Entity()
@Entity({ name: 'todo_item' })
export class TodoItemEntity {
@PrimaryGeneratedColumn()
id!: string;
id!: number;

@Column()
title!: string;
Expand Down
1 change: 1 addition & 0 deletions examples/nest-graphql-typeorm/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"include": [
"src",
"migrations",
"seeds.ts",
"ormconfig.json"
],
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion examples/nest-graphql-typeorm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"outDir": "./dist",
"rootDir": "."
},
"include": ["src", "test", "migrations", "ormconfig.json"],
"include": ["src", "test", "migrations", "seeds.ts", "ormconfig.json"],
"exclude": ["node_modules", "dist"]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// this is needed to create a query builder in typeorm :(
import { Connection, createConnection, getConnection } from 'typeorm';
import { TestEntityRelationEntity } from './test-entity-relation.entity';
import { TestRelation } from './test-relation.entity';
import { TestEntity } from './test.entity';

Expand All @@ -8,7 +9,7 @@ export function createTestConnection(): Promise<Connection> {
type: 'sqlite',
database: ':memory:',
dropSchema: true,
entities: [TestEntity, TestRelation],
entities: [TestEntity, TestRelation, TestEntityRelationEntity],
synchronize: true,
logging: false,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Entity, JoinColumn, PrimaryColumn, ManyToOne } from 'typeorm';
import { TestRelation } from './test-relation.entity';
import { TestEntity } from './test.entity';

@Entity()
export class TestEntityRelationEntity {
@PrimaryColumn({ name: 'test_relation_id' })
testRelationId!: string;

@PrimaryColumn({ name: 'test_entity_id' })
testEntityId!: string;

@ManyToOne(() => TestRelation, (tr) => tr.testEntityRelation)
@JoinColumn({ name: 'test_relation_id' })
testRelation?: TestRelation;

@ManyToOne(() => TestEntity, (te) => te.testEntityRelation)
@JoinColumn({ name: 'test_entity_id' })
testEntity?: TestEntity;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { ManyToOne, Column, PrimaryGeneratedColumn, Entity, JoinColumn, ManyToMany, OneToOne } from 'typeorm';
import {
ManyToOne,
Column,
PrimaryGeneratedColumn,
Entity,
JoinColumn,
ManyToMany,
OneToOne,
OneToMany,
} from 'typeorm';
import { TestEntityRelationEntity } from './test-entity-relation.entity';
import { TestEntity } from './test.entity';

@Entity()
Expand All @@ -21,4 +31,7 @@ export class TestRelation {

@OneToOne(() => TestEntity, (entity) => entity.oneTestRelation)
oneTestEntity?: TestEntity;

@OneToMany(() => TestEntityRelationEntity, (ter) => ter.testRelation)
testEntityRelation?: TestEntityRelationEntity;
}
4 changes: 4 additions & 0 deletions packages/query-typeorm/__tests__/__fixtures__/test.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
OneToOne,
JoinColumn,
} from 'typeorm';
import { TestEntityRelationEntity } from './test-entity-relation.entity';
import { TestRelation } from './test-relation.entity';

@Entity()
Expand Down Expand Up @@ -37,4 +38,7 @@ export class TestEntity {
@OneToOne(() => TestRelation, (relation) => relation.oneTestEntity)
@JoinColumn()
oneTestRelation?: TestRelation;

@OneToMany(() => TestEntityRelationEntity, (ter) => ter.testEntity)
testEntityRelation?: TestEntityRelationEntity;
}
Loading

0 comments on commit 6b80bea

Please sign in to comment.