How to use the typeorm-typedi-extensions.InjectConnection function in typeorm-typedi-extensions

To help you get started, we’ve selected a few typeorm-typedi-extensions 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 rotemgrim / rooster-x / src / main / repositories / UserRepository.ts View on Github external
import {Container, Service} from "typedi";
import {Connection} from "typeorm";
import {InjectConnection} from "typeorm-typedi-extensions";
import {User} from "../../entity/User";
import {UserEpisode} from "../../entity/UserEpisode";
import {UserMetaData} from "../../entity/UserMetaData";
import * as path from "path";
import * as fs from "fs";
import AppGlobal from "../helpers/AppGlobal";

@Service()
export class UserRepository {

    @InjectConnection("reading")
    private connection: Connection;

    public getAllUsers() {
        const userRepo = this.connection.manager.getRepository(User);
        return userRepo.find();
    }

    public getUser(id) {
        console.log("find user by id", id);
        const userRepo = this.connection.manager.getRepository(User);
        return userRepo.findOne(id);
    }

    public createUser(payload: User) {
        console.log(payload);
        const userRepo = this.connection.manager.getRepository(User);
github rotemgrim / rooster-x / src / main / repositories / TorrentsRepository.ts View on Github external
import {MetaData} from "../../entity/MetaData";
import RoRest from "../services/RoRest";
import {HTMLElement, parse} from "node-html-parser";
import {TorrentFile} from "../../entity/TorrentFile";
import {IMediaEntry} from "../../common/models/IMediaEntry";
import * as ptn from "../../common/lib/parse-torrent-name";
import {MediaRepository} from "./MediaRepository";
import IMDBController from "../controllers/IMDBController";
import {Alias} from "../../entity/Alias";

type TorrentLinks = Array<{title: string, magnet: string, timestamp: number}>;

@Service()
export class TorrentsRepository {

    @InjectConnection("reading")
    private connection: Connection;

    public static startTorrentsWatch(): void {
        setInterval(() => {
            const d = new Date();
            const minutes = d.getMinutes();
            const hours = d.getHours();
            if (hours === 18 && minutes >= 15 && minutes < 45) {
                Container.get(TorrentsRepository).reprocessTorrents()
                    .catch(console.error);
            }
        }, 1800 * 1000);
    }

    public async getAllTorrents() {
        const metaRepo = this.connection.manager.getRepository(MetaData);
github rotemgrim / rooster-x / src / main / repositories / GenreRepository.ts View on Github external
import {Container, Service} from "typedi";
import {Connection} from "typeorm";
import {InjectConnection} from "typeorm-typedi-extensions";
import {Genre} from "../../entity/Genre";
import {MetaData} from "../../entity/MetaData";
import MediaController from "../controllers/MediaController";

@Service()
export class GenreRepository {

    @InjectConnection("reading")
    private connection: Connection;

    public getAllGenres() {
        const userRepo = this.connection.manager.getRepository(Genre);
        return userRepo.find();
    }

    public async reprocessAllGenres() {
        const metaRepo = this.connection.manager.getRepository(MetaData);
        const allMeta = await metaRepo.find();
        let allGenres: string[] = [];
        if (allMeta) {
            for (const meta of allMeta) {
                if (meta && meta.genres) {
                    const genres = meta.genres.split(", ") as string[];
                    if (genres) {
github rotemgrim / rooster-x / src / main / repositories / MediaRepository.ts View on Github external
constructor(
        @InjectConnection("reading") private connection: Connection,
    ) {
        this.episodeRepo = this.connection.getRepository(Episode);
        this.metaRepo = this.connection.getRepository(MetaData);
        this.aliasRepo = this.connection.getRepository(Alias);
        this.filesRepo = this.connection.getRepository(MediaFile);
        this.torrentFileRepo = this.connection.getRepository(TorrentFile);
    }
github rotemgrim / rooster-x / src / main / controllers / FilesController.ts View on Github external
constructor(
        @InjectConnection("reading") private connection: Connection,
    ) {
        this.filesRepo = this.connection.getRepository(MediaFile);
        this.metaDataRepo = this.connection.getRepository(MetaData);
        this.episodeRepo = this.connection.getRepository(Episode);
        this.aliasRepo = this.connection.getRepository(Alias);
    }

typeorm-typedi-extensions

Dependency injection and service container integration with TypeORM using TypeDI library.

MIT
Latest version published 4 years ago

Package Health Score

54 / 100
Full package analysis

Similar packages