Coder Social home page Coder Social logo

knex-tiny-logger's Introduction

knex-tiny-logger

Zero config queries logger for knex

Usage

Install the package:

$ yarn add knex-tiny-logger

Apply knex-tiny-logger to knex instance:

import createKnex from 'knex'
import knexTinyLogger from 'knex-tiny-logger'

const knexOptions = {} // Your knex config
const knex = createKnex(knexOptions)
knexTinyLogger(knex)

// alternative
// knex-tiny-logger returns knex instance
// so you can do like this
const knex = knexTinyLogger(createKnex(knexOptions))

Advanced usage

By default knex-tiny-logger uses console.log, but you can specify any logger which your prefer:

import createKnex from 'knex'
import knexTinyLogger from 'knex-tiny-logger'
import initDebug from 'debug'

const awesomeLogger = initDebug('my-project:knex')
const knexOptions = {} // Your knex config
const knex = createKnex(knexOptions)
knexTinyLogger(knex, { logger: awesomeLogger })

Also you can disable bindings:

knexTinyLogger(knex, { bindings: false })

License

MIT

knex-tiny-logger's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

knex-tiny-logger's Issues

Issue with Knex > 0.95

Hi, thank you for the great library.

Recently Knex released a HUGE release 0.95.0 and it contains breaking changes and knex-tiny-logger not working with an error knex.client._formatQuery is not a function.

https://github.com/knex/knex/releases/tag/0.95.0

Replace knex.client._formatQuery with require('knex/lib/execution/internal/query-executioner').formatQuery fixes the issue.

Can I create a PR for this?

Downside of require('knex/lib/execution/internal/query-executioner').formatQuery is: 1) it is a breaking change 2) it is a private API which should be avoided.

Typescript typings broken with Knex > 0.95

Related to #9, the Typescript typings are broken when using this package with the latest version of Knex:

node_modules/knex-tiny-logger/typings/index.d.ts:10:46 - error TS2709: Cannot use namespace 'Knex' as a type.

    export default function knexTinyLogger(knex: Knex, options?: KnexTinyLoggerOptions): Knex
                                                ~~~~

node_modules/knex-tiny-logger/typings/index.d.ts:10:86 - error TS2709: Cannot use namespace 'Knex' as a type.

    export default function knexTinyLogger(knex: Knex, options?: KnexTinyLoggerOptions): Knex

In my code I had to change:

import Knex from 'knex'

to:

import { Knex } from 'knex'

So it's probably something similar here.

  • knex-tiny-logger 2.1.0
  • knex 0.95.4
  • typescript 4.2.4

lib/index.js removes flow typing

I'm importing knex-tiny-logger into my nodejs project that uses flowtype and I have to setup a flowtyped file containing the very definitions already in src/index.js. Is there a way to publish the file and preserve the flowtyping for those of us who want to check the types?

https://github.com/flow-typed/flow-typed/wiki/FAQs#what-is-the-preferred-way-for-a-module-to-provide-its-own-libdef

Copying them to index.js.flow or something like that looks to be the preferred method.

Add sql query highlighting

Hey ๐Ÿ‘‹

I was using very similar plugin for knex logging and decided to publish it or find a similar one. I found this package and tried it. It fits my needs, the only thing I miss is syntax highlighting, I have it in mine and it helps in reading queries.

Here is an example of a small query (top - this package, bottom - mine):

Screen Shot 2019-04-27 at 04 30 36

It helps even more with larger queries and also looks same way as in some sql clients, for example postico (I'm using it), same query:

Screen Shot 2019-04-27 at 04 35 22

So, the question is if you are okay with this feature? I can add a PR with it.

Thanks

Skip long queries?

We sometimes need to insert binary blobs into the DB, which overflows the entire console buffer and hangs the server for a while when debugging
I would like an option to limit individual queries to e.g. first 1KB
Please advise
image

Query Binding is not working

In previous versions of knex it worked perfectly but now it just show the query without the params

Ex.:
SQL (2.508 ms) select * from "users" where "id" = $1

Im using the last version of dependencies:

  "knex": "^0.95.4"
  "knex-tiny-logger": "^2.1.0"

My config file:

import knex from 'knex';
import knexTinyLogger from 'knex-tiny-logger';
import knexfile from '../../knexfile';

const knexconf = knex(knexfile.development);

module.exports = knexTinyLogger(knexconf, { bindings: true });

logger incorrectly logs selects where column = 0

eg

SQL (4.097 ms) select * from `test` where `numbercol` = and `time` < 1535796000

Probably caused by bindings[index] being false in
const binding = bindings[index] ? JSON.stringify(bindings[index]) : ''

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.