question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Entity schemas documentation

See original GitHub issue

Issue type:

[x] question [ ] bug report [ ] feature request [x] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [x] mysql / mariadb [ ] oracle [ ] postgres [ ] sqlite [ ] sqljs [ ] react-native

TypeORM version:

[ ] latest [x] @next [ ] 0.x.x (or put your version here)

Hey how well implemented are entity schemas at this point? I see some documentation has emerged recently. I would like to see some examples how different decorators get translated in the schema files like GeneratedColumn, CreateDateColumn, UpdateDateColumn.

If i remove the decorators on the entities and create schema files targeting these entities instead then will my existing code (repositories/query-builders/enitity-manager) work without needing any additional modifications?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jebbdomingocommented, Jan 22, 2019

Any example how to apply the separate schema to an entity?

1reaction
johannesschobelcommented, Mar 1, 2019

Hey @jebbdomingo , I managed to solve it like this:

const userRepository = getRepository<User>('UserSchema');
const user = await userRepository.findOne(1);

Whereas User is the Interface and UserSchema is the EntitySchema that describes the User. Respective UserSchema may look like this:

import { EntitySchema } from 'typeorm';
import { User } from './user.entity';

export const UserSchema = new EntitySchema<User>({
  name: 'UserSchema',
  tableName: 'users',

  columns: {
    id: {
      type: 'uuid',
      primary: true,
      generated: 'uuid',
    },

    email: {
      type: 'varchar',
      length: 150,
      unique: true,
    },
    username: {
      type: 'varchar',
      length: 150,
      unique: true,
    },
    password: {
      type: 'varchar',
      length: 150,
    },

    createdAt: {
      name: 'created_at',
      type: 'timestamp with time zone',
      createDate: true,
    },
    updatedAt: {
      name: 'updated_at',
      type: 'timestamp with time zone',
      updateDate: true,
    }
  },
  indices: [
    // ...
  ],
  relations: {
    // ...
  }
});

again, the User in this schema description is the previously mentioned Interface!

Maybe this helps?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create schema documents for the Common Data Model
Manifest, A collection of all your schema documents that acts as the entry point to your Common Data Model entities.
Read more >
Entity Schemas - FireCMS
This is unreleased documentation for FireCMS 1.0.0 version. ... properties Object defining the properties for the entity schema.
Read more >
Defining an entity schema - IBM
An entity schema is a set of entities and the relationships between the entities. In an eXtreme Scale application with multiple partitions, the ......
Read more >
Schema Entities - Cloudera Documentation
Schema Entities. You can use Schema Registry to work with three types of schema entities: Schema entities. This table provides a more detailed...
Read more >
Entity and schema API — followthemoney documentation
A collection of all the schemata available in followthemoney. The model provides some helper functions to find schemata, properties or to instantiate entity...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found