npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

repovych-knex

v1.1.2

Published

Knex realization of repovych repository interface

Readme

repovych-knex

Knex realization of Repovych reposytory abstraction (see https://gitflic.ru/project/pantagruel74/repovych)

Example of usage

//class-model. see https://gitflic.ru/project/pantagruel74/class-model
const UserRecord {
    @property(null,
        valid.number(),
        make.int()
    )
    id: number;

    @property(null,
        valid.string(s => !!s.length),
        make.string()
    )
    name: string;
}

type UserQuery = {
    ids: number[],
}

const conn KnexovychConnection.createMysql({
    host: '127.0.0.1',
    port: 3306,
    user: 'your_database_user',
    password: 'your_database_password',
    database: 'myapp_test',
});

const log = new ConsoleLoggych();

const migration = new KnexovychMigrationManager(conn, log);
await migration.lastest();

const repo: IRepovych<UserRecord, Partial<UserQuery>, {id: string}> = 
    new RepovychKnexovych(
        conn,
        "users",
        (q, k) => (!!q.ids) ? k.whereIn("id", q.ids) : k,
        () => new UserRecord(),
        log
    );

await repo.save([{id: 1, name: "admin"}, {id: 2, name: "guest"}]);
const result = await repo.query({ids: [2]});
console.log(result); //=> [{id: 2, name: "guest"}]

API

Connection:

export type MigrationsConf = {
    extension: string,
    directory: string,
    stub?: string,
    tableName?: string,
    schemaName?: string,
    disableTransactions?: boolean,
    disableMigrationsListValidation?: boolean,
    sortDirsSeparately?: boolean,
    loadExtensions?: string[],
    migrationSource?: any,
}

export type SeedsConf = {
    directory: string,
    extension: string,
    loadExtensions?: string,
    recursive?: boolean,
    specific?: any,
    sortDirsSeparately?: boolean,
    seedSource?: any,
    timestampFilenamePrefix?: any,
}

export class KnexovychConnection
{
    //Agile constructor by knex config. Special costructors in static methods
    public constructor(conf: any);

    public runInConnection(f: (k: Knex) => Promise<any>, timeout = 10000): Promise<any>;

    public runInTransaction(f: (k: Knex) => (Knex.QueryBuilder|Promise<any>), timeout = 10000): Promise<any>;

    public updateConnection();

    public updateConnectionIfExpired(expiredMsDiff: number);

    public updateConnectionLater(delayMs: number = 5000);

    public shutdown();

    private static makeKnexovichConnection(
        client: string,
        conn: any,
        migrations: MigrationsConf|null, 
        seeds: SeedsConf|null,
        pool: {min: number, max: number}|null,
        extra: {}
    ): KnexovychConnection;

    public static createMysql(conn: {
            host: string,
            port: number,
            user: string,
            password: string,
            database: string,
        }, 
        migrations: MigrationsConf|null = null, 
        seeds: SeedsConf|null = null,
        version: string|null = null,
        pool: {min: number, max: number}|null = null
    ): KnexovychConnection;

    public static createOracledb(conn: {
            host: string,
            port?: number,
            user: string,
            password: string,
            database: string,
            odbc?: string
        }, 
        migrations: MigrationsConf|null = null, 
        seeds: SeedsConf|null = null,
        version: string|null = null,
        pool: {min: number, max: number}|null = null
    ): KnexovychConnection;

    public static createMssql(conn: {
            server: string,
            port: number,
            user: string,
            password: string,
            database: string,
        }, 
        migrations: MigrationsConf|null = null, 
        seeds: SeedsConf|null = null,
        version: string|null = null,
        pool: {min: number, max: number}|null = null
    ): KnexovychConnection;

    public static createSqlite(conn: {
            filename: string,
            flags?: string[],
            options?: any,
        },
        migrations: MigrationsConf|null = null, 
        seeds: SeedsConf|null = null,
        version: string|null = null,
        pool: {min: number, max: number}|null = null
    ): KnexovychConnection;

    public static createSqlite3(conn: {
            filename: string,
            flags?: string[],
            options?: any,
        },
        migrations: MigrationsConf|null = null, 
        seeds: SeedsConf|null = null,
        version: string|null = null,
        pool: {min: number, max: number}|null = null
    ): KnexovychConnection;

    public static createBetterSqlite3(conn: {
            filename: string,
            flags?: string[],
            options?: any,
        },
        migrations: MigrationsConf|null = null, 
        seeds: SeedsConf|null = null,
        version: string|null = null,
        pool: {min: number, max: number}|null = null
    ): KnexovychConnection;

    public static createPgSearchPath(conn: {
            searchPath: string[],
        },
        migrations: MigrationsConf|null = null, 
        seeds: SeedsConf|null = null,
        version: string|null = null,
        pool: {min: number, max: number}|null = null
    ): KnexovychConnection;

    public static createPg(conn: {
            connectionString: string,
            host: string,
            port: number,
            user: string,
            database: string,
            password: string,
            ssl?: any,
        },
        migrations: MigrationsConf|null = null, 
        seeds: SeedsConf|null = null,
        version: string|null = null,
        pool: {min: number, max: number}|null = null
    ): KnexovychConnection;

    public static createPostgres(conn: {
            connectionString: string,
            host: string,
            port: number,
            user: string,
            database: string,
            password: string,
            ssl?: any,
        },
        migrations: MigrationsConf|null = null, 
        seeds: SeedsConf|null = null,
        version: string|null = null,
        pool: {min: number, max: number}|null = null
    ): KnexovychConnection;
}

Migration:

export class KnexovychMigrationManager
{
    public constructor(conn: KnexovychConnection, log: ILoggych);

    public async make(name: string): Promise<void>;

    public async up(): Promise<void>;

    public async down(): Promise<void>;

    public async lastest(): Promise<void>;

    public async rollback(): Promise<void>;
}

Repo:

export class RepovychKnexovych<T extends S, Q, S extends {}> 
    implements IRepovich<T, Q, S> 
{
    public conn: KnexovychConnection;
    public tablename: string;
    public queryProcess: (q: Q, k: Knex.QueryBuilder) => Knex.QueryBuilder;
    public idFields: (keyof S)[];
    public newModel: () => T;
    public log: ILoggych;

    constructor(
        conn: KnexovychConnection, 
        tablename: string, 
        queryProcess: (q: Q, k: Knex.QueryBuilder) => Knex.QueryBuilder,
        idFields: (keyof S)[],
        newModel: () => T,
        log: ILoggych
    );

    public async query(q: Q): Promise<T[]>;

    private getId<A extends S>(v: A): S;

    public async delete(ids: S[]): Promise<void>;

    public async queryDelete(q: Q): Promise<void>;

    public async save(d: T[]): Promise<void>;

    public modify<Q1 extends {}, T2 extends S>(
        queryMod: (q: Q1, k: Knex.QueryBuilder) => Knex.QueryBuilder,
        newModel: () => T2
    ): RepovychKnexovych<T2, Q & Q1, S>;
}

Repov2:

export class RepovychKnexovych2<T extends S, Q, S extends {}> 
    implements IRepovich2<T, Q, S> 
{
    public conn: KnexovychConnection;
    public tablename: string;
    public queryProcess: (q: Q, k: Knex.QueryBuilder) => Knex.QueryBuilder;
    public idFields: (keyof S)[];
    public newModel: () => T;
    public log: ILoggych;

    constructor(
        conn: KnexovychConnection, 
        tablename: string, 
        queryProcess: (q: Q, k: Knex.QueryBuilder) => Knex.QueryBuilder,
        idFields: (keyof S)[],
        newModel: () => T,
        log: ILoggych
    );

    public async query(q: Q): Promise<T[]>;

    private getId<A extends S>(v: A): S;

    public async delete(ids: S[]): Promise<void>;

    public async queryDelete(q: Q): Promise<void>;

    public async save(d: T[]): Promise<void>;

    public modify<Q1 extends {}, T2 extends S>(
        queryMod: (q: Q1, k: Knex.QueryBuilder) => Knex.QueryBuilder,
        newModel: () => T2
    ): RepovychKnexovych<T2, Q & Q1, S>;

    public async count(q: Q): Promise<number>;

    public async reset(d: T[]): Promise<void>;

    public async queryIds(q: Q): Promise<T[]>;
}

Author

Anatoly Starodubtsev [email protected]

License

MIT