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 🙏

© 2024 – Pkg Stats / Ryan Hefner

egg-kmore

v22.6.0

Published

egg plugin of kmore

Downloads

218

Readme

egg-kmore

kmore for midway framework.

Version License Conventional Commits

Installation

npm install egg-kmore knex

# Then add one of the following:
npm install pg
npm install mssql
npm install oracle
npm install sqlite3

Configuration

Enable Plugin

Edit ${app_root}/src/config/plugin.ts:

import { EggPlugin } from 'midway'

export default {
  kmore: {
    enable: true,
    package: 'egg-kmore',
  },
} as EggPlugin

Add Configurations

/* location: ${app_root}/src/config/config.${env}.ts */

import { EggKmoreConfig, genTbListFromType, ClientOpts } from 'egg-kmore'
import { TbListModel } from '../app/user/user.model'

const master: ClientOpts = {
  knexConfig: {
    client: 'pg',
    connection: {
      host: 'localhost',
      user: 'postgres',
      password: '',
      database: 'db_ci_test',
    },
    acquireConnectionTimeout: 10000,
  },
  tables: genTbListFromType<TbListModel>(),
}

// app: default true
export const kmore: EggKmoreConfig = {
  client: master,
}


/* location: ../app/user/user.model.ts */
export interface TbListModel {
  tb_user: User
  tb_user_detail: UserDetail
}

/**
 * user info
 */
export interface UserInfo extends User, UserDetail {
}

export interface User {
  uid: number
  user_name: string
}
export interface UserDetail {
  uid: number
  phone: string
  email: string
}

export interface GetUserOpts {
  uid: number
}

Usage

/* location: ../app/user/user.service.ts */

import { provide, plugin } from 'midway'
import { DbModel } from 'egg-kmore'
import { GetUserOpts, UserInfo, User, TbListModel } from './user.model'

@provide()
export class UserService {

  constructor(
    @plugin('kmore') private readonly db: DbModel<TbListModel>,
  ) { }

  /**
   * Read user info
   */
  public async getUser(options: GetUserOpts): Promise<UserInfo> {
    const { rb, tables: t } = this.db

    const row: UserInfo = await rb.tb_user()
      .innerJoin(
        t.tb_user_detail,
        `${t.tb_user}.uid`,
        `${t.tb_user_detail}.uid`,
      )
      .select('*')
      .where(`${t.tb_user}.uid`, options.uid)
      .then(rows => rows[0])

    return row
  }

  /**
   * Read user_name
   */
  public async getUserName(options: GetUserOpts): Promise<User['user_name']> {
    const { rb } = this.db

    const name = await rb.tb_user()
      .select('user_name')
      .where('uid', options.uid)
      .then(rows => rows[0] ? rows[0].user_name : '')

    return name
  }

}

Generating source files pre build

The files generated automatically under typescript environment for debug or test

cd ${app_root}
kmore gen --path ./src

// then you could build the project
npm run build

License

MIT

Languages