Skip to content

Instantly share code, notes, and snippets.

View peshkov3's full-sized avatar

Peshkov Maxim peshkov3

  • Finverity
  • UK
View GitHub Profile
@recurrence
recurrence / snake_naming.ts
Created November 21, 2017 16:34
TypeORM Snake Case Naming Strategy
import { NamingStrategyInterface, DefaultNamingStrategy } from 'typeorm'
import { snakeCase } from 'typeorm/util/StringUtils'
export class SnakeNamingStrategy extends DefaultNamingStrategy implements NamingStrategyInterface {
tableName(className: string, customName: string): string {
return customName ? customName : snakeCase(className)
}
columnName(propertyName: string, customName: string, embeddedPrefixes: string[]): string {
return snakeCase(embeddedPrefixes.join('_')) + (customName ? customName : snakeCase(propertyName))
@ionutmilica
ionutmilica / knex-paginator.js
Last active June 6, 2019 13:18
Simple paginator function for knex
module.exports = (knex) => {
return async (query, options) => {
const perPage = options.perPage || 10;
let page = options.page || 1;
const countQuery = knex.count('* as total').from(query.clone().as('inner'));
if (page < 1) {
page = 1;
}