How to use the typeorm.Index function in typeorm

To help you get started, we’ve selected a few typeorm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mpcast / mpcast-server / packages / core / src / entity / options / option.entity.ts View on Github external
import { IsJSON } from 'class-validator';
import { Entity, Index, PrimaryColumn } from 'typeorm';
import { Column } from 'typeorm';

@Entity('options')
@Index(['key'])
export class Option {
  // constructor(input?: DeepPartial<option>) {
  // }
  @Column({ type: 'varchar', length: 100 })
  @PrimaryColumn()
  key: string;

  @Column('json', {
    nullable: true,
    comment: '元信息值',
  })
  @IsJSON()
  value?: any;

  @Column('varchar', {
    nullable: true,</option>
github kinecosystem / marketplace-server / scripts / src / models / orders.ts View on Github external
sender: User;
	recipient: User;
	senderMeta: OrderMeta;
	recipientMeta: OrderMeta;
	contexts: [OrderContext, OrderContext];
};

@Entity({ name: "orders" })
@Initializers({
	contexts: () => [],
	id: () => generateId(IdPrefix.Transaction),
	currentStatusDate: () => moment().toDate(),
	expirationDate: () => moment().add(10, "minutes").toDate() // opened expiration
})
@Index(["offerId", "nonce"])
@Index(["offerId", "status"])
@Register
class OrderImpl extends CreationDateModel implements Order {
	@Column()
	public readonly origin!: OrderOrigin;

	@Column("simple-json", { name: "blockchain_data", nullable: true })
	public blockchainData!: BlockchainData;

	@OneToMany(type => OrderContext, context => context.order, {
		cascadeInsert: true,
		cascadeUpdate: true
	})
	public contexts!: OrderContext[];

	@Index()
	@Column({ name: "offer_id" })
github ScuroGuardiano / Dark-Nova / src / db / models / planet.ts View on Github external
This file and project is licensed under the MIT license
See file LICENSE in the root of this project or go to  for full license details.
*/

import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, BaseEntity, Index, ManyToOne, JoinColumn, OneToOne, AfterLoad } from 'typeorm';
import Player from './player';
import PlanetBuildings from './planet-buildings';
import IPlanetData from '../../game/data-types/planet-data';
import { IResourcesAndEnergy } from '../../game/data-types/resources';
import IEconomyData from '../../game/data-types/economy-data';
import EconomyCalculator from '../../game/core/services/economy-calculator';
import Defense from './defense';
import Ships from './ships';

@Entity()
@Index(['galaxy', 'system', 'position'], { unique: true })
export default class Planet extends BaseEntity implements IResourcesAndEnergy {
    //TODO: Zone
    public get energy(): number {
        return this.economyData.energy.production;
    }
    public get usedEnergy(): number {
        return this.economyData.energy.usage;
    }
    public get usedFields(): number {
        const buildingsList = this.buildings.getBuildingsList();
        const totalBuildings = buildingsList.reduce((previous, current) =&gt; {
            return previous + current.level;
        }, 0);
        return totalBuildings;
    }
    public get metalPerHour(): number {
github SolidZORO / leaa / packages / _leaa-common / src / entrys / ax.entity.ts View on Github external
import { Index, Entity, Column } from 'typeorm';
import { ObjectType, Field, Int } from 'type-graphql';
import { AxAttachmentsObject } from '@leaa/common/src/dtos/ax';

import { Base } from '@leaa/common/src/entrys';

@Entity('axs')
@Index('axs_title_unique', ['title'], { unique: true })
@Index('axs_slug_unique', ['slug'], { unique: true })
@ObjectType()
export class Ax extends Base {
  @Column({ type: 'varchar', length: 32, unique: true })
  @Field(() => String)
  title!: string;

  @Column({ type: 'varchar', length: 32, unique: true, default: null })
  @Field(() => String, { nullable: true })
  slug?: string;

  @Column({ type: 'text', nullable: true })
  @Field(() => String, { nullable: true })
  description?: string;

  @Column({ type: 'int', default: 0 })
github velopert / velog-server / src / entity / SeriesPosts.ts View on Github external
Index,
  UpdateDateColumn,
  CreateDateColumn,
  OneToOne,
  JoinColumn,
  ManyToOne,
  getRepository
} from 'typeorm';
import Post from './Post';
import Series from './Series';
import DataLoader from 'dataloader';

@Entity('series_posts', {
  synchronize: false
})
@Index(['fk_series_id', 'fk_post_id'])
export default class SeriesPosts {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Index()
  @Column('uuid')
  fk_series_id!: string;

  @Index()
  @Column('uuid')
  fk_post_id!: string;

  @Column('int4')
  index!: number;

  @Column('timestampz')
github poggit / poggit / server / model / release / Release.ts View on Github external
@Column() isFeatured: boolean
	@Column() callsHome: boolean
	@Column() callsThirdParty: boolean

	@OneToMany(() =&gt; ReleaseAuthor, author =&gt; author.release) authors: Promise
	@Column({type: "enum", enum: getEnumNames(CategoryType)}) category: keyof CategoryType
	@OneToMany(() =&gt; ReleaseCategory, category =&gt; category.release) minorCategories: Promise

	@OneToMany(() =&gt; ReleaseVersion, version =&gt; version.release) versions: Promise

	@OneToMany(() =&gt; ReleasePermission, version =&gt; version.release) permissions: Promise
	@OneToMany(() =&gt; ReleaseCommand, version =&gt; version.release) commands: Promise
}

@Entity()
@Index(["author", "release"], {unique: true})
export class ReleaseAuthor implements IReleaseAuthor{
	@PrimaryGeneratedColumn() id: number
	@ManyToOne(() =&gt; User) author: Promise
	@ManyToOne(() =&gt; Release, release =&gt; release.authors) release: Promise
	@Column({type: "enum", enum: getEnumNames(AuthorType)}) type: keyof AuthorType
}

@Entity()
export class ReleaseCategory implements IReleaseCategory{
	@PrimaryGeneratedColumn() id: number
	@ManyToOne(() =&gt; Release, release =&gt; release.minorCategories) release: Promise
	@Column({type: "enum", enum: getEnumNames(CategoryType)}) category: keyof CategoryType
}

@Entity()
export class ReleasePermission implements IReleasePermission{
github lonelyhentai / minellius / server / src / data / entities / current-record.entity.ts View on Github external
@Entity({
  name: 'current',
})
export class CurrentRecordEntity {
  @PrimaryGeneratedColumn({
    type: 'int',
  })
  id!: number;

  @Column({
    name: 'keyword',
    type: 'varchar',
    nullable: false,
  })
  @Index('current_keyword_uindex',{
    unique: true
  })
  keyword!: string;

  @Column({
    name: 'dict',
    type: 'text',
    nullable: false
  })
  value!: string;
}
github ShipChain / engine / src / entity / EventSubscription.ts View on Github external
resolve(body);
        });
    });
}

export class EventSubscriberAttrs {
    url: string;
    project: string;
    receiverType?: string;
    eventNames?: string[];
    lastBlock?: number;
    interval?: number;
}

@Entity()
@Index('URL_PROJECT_INDEX', ['url', 'project'], { unique: true })
export class EventSubscription extends BaseEntity {
    @PrimaryGeneratedColumn('uuid') id: string;
    @Column() url: string;
    @Column() project: string;
    @Column() receiverType: string;
    @Column('simple-array') eventNames: string[];
    @Column('bigint') lastBlock: number;
    @Column('int') interval: number;
    @Column('int') errorCount: number;
    @CreateDateColumn() createdDate: Date;

    private contractInstance: any;
    private contractEntity: Contract;
    private asyncPolls: any = {};

    static DEFAULT_INTERVAL = 30 * SECONDS;
github rotemgrim / rooster-x / src / entity / Episode.ts View on Github external
import "reflect-metadata";
import {Entity, Column, OneToMany, ManyToOne, Index} from "typeorm";
import {MediaFile} from "./MediaFile";
import {MetaData} from "./MetaData";
import {AbsMetaData} from "./AbsMetaData";
import {UserEpisode} from "./UserEpisode";
import {TorrentFile} from "./TorrentFile";

@Entity("Episode")
@Index(["season", "episode", "metaData"], { unique: true })
export class Episode extends AbsMetaData {

    @Column({type: "int", nullable: true})
    public season?: number;

    @Column({type: "int"})
    public episode: number;

    @Index()
    @Column({type: "varchar", length: 255, nullable: true})
    public imdbSeriesId?: string;

    @OneToMany(() => MediaFile, mediaFile => mediaFile.episode, {eager: true})
    public mediaFiles: MediaFile[];

    @OneToMany(() => TorrentFile, torrentFile => torrentFile.episode, {eager: true})
github ahmetuysal / nest-hackathon-starter / src / user / user.entity.ts View on Github external
import { User as IUser } from '../contract';
import { Entity, Unique, Index, PrimaryGeneratedColumn, Column } from 'typeorm';
import {
  IsBoolean,
  IsEmail,
  IsLowercase,
  IsNotEmpty,
  IsOptional,
  IsUrl,
  MaxLength,
  Matches,
} from 'class-validator';
@Entity('user')
@Unique('unique_user_username', ['username'])
@Unique('unique_user_email', ['email'])
@Index('index_user_username', ['username'])
@Index('index_user_email', ['email'])
export class User implements IUser {
  @PrimaryGeneratedColumn()
  id: number;

  @Matches(RegExp('^[a-zA-Z0-9\\-]+$'))
  @MaxLength(32)
  @IsLowercase()
  @Column('text')
  username: string;

  @IsEmail()
  @Column('text')
  email: string;

  @IsNotEmpty()