quaerateum
Version:
Simple typescript ORM for node.js based on data-mapper, unit-of-work and identity-map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JS.
22 lines (18 loc) • 826 B
text/typescript
import { MetadataStorage } from '../metadata';
import { ReferenceType } from '../entity';
import { EntityProperty, IEntity, PropertyOptions } from '.';
import { Utils } from '../utils';
export function PrimaryKey(options: PrimaryKeyOptions = {}): Function {
return function (target: IEntity, propertyName: string) {
const meta = MetadataStorage.getMetadata(target.constructor.name);
options.name = propertyName;
meta.primaryKey = propertyName;
meta.properties[propertyName] = Object.assign({ reference: ReferenceType.SCALAR, primary: true }, options) as EntityProperty;
Utils.lookupPathFromDecorator(meta);
};
}
export interface PrimaryKeyOptions extends PropertyOptions {
name?: string;
type?: any;
}
export type IPrimaryKey = number | string | { toString?(): string, toHexString?(): string };