Giter Site home page Giter Site logo

prisma-query-log's Introduction

prisma-query-log

Log prisma query event. Currently works only for SQLite, MySQL.

Features:

  • Substitute parameters
  • Remove backticks and database prefix

Install

npm install --save-dev prisma-query-log

Usage

import { createPrismaQueryEventHandler } from 'prisma-query-log';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient({
    log: [
        {
            level: 'query',
            emit: 'event',
        },
    ],
});

const log = createPrismaQueryEventHandler();

prisma.$on('query', log);

API

function createPrismaQueryEventHandler(
    options?: CreatePrismaQueryEventHandlerArgs,
): (event: PrismaQueryEvent) => void;

const defaultOptions = {
    /**
     * Boolean of custom log function,
     * if true `console.log` will be used,
     * if false noop - logs nothing.
     */
    logger: true as boolean | ((query: string) => unknown),
    /**
     * Remove backticks.
     */
    unescape: true,
    /**
     * Color of query (ANSI escape code)
     */
    colorQuery: undefined as undefined | string,
    /**
     * Color of parameters (ANSI escape code)
     */
    colorParameter: undefined as undefined | string,
    /**
     * Format SQL query,
     * colorQuery/colorParameter will be ignored.
     */
    format: false,

    /**
     * Formatter options
     * https://github.com/mtxr/vscode-sqltools/tree/master/packages/formatter#options
     */

    /**
     * Show Query Duration, default is false
     */
    queryDuration: false as boolean,

    /**
     * Query language, default is Standard SQL
     */
    language: undefined as 'sql' | 'n1ql' | 'db2' | 'pl/sql' | undefined,
    /**
     * Characters used for indentation
     */
    indent: '    ',
    /**
     * How to change the case of reserved words
     */
    // eslint-disable-next-line unicorn/no-null
    reservedWordCase: null as 'upper' | 'lower' | null,
    /**
     * How many line breaks between queries
     */
    linesBetweenQueries: 1 as number | 'preserve',
};

Other projects

https://github.com/unlight/nestolog - Logger for NestJS, implements LoggerService

Screenshots

Before

After

Development

docker run -it -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=user postgres
docker run -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=query_log_example_db mysql

prisma-query-log's People

Contributors

dok6n avatar reyronald avatar semantic-release-bot avatar unlight avatar

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

Watchers

 avatar  avatar  avatar

prisma-query-log's Issues

Todo

  • where x in (x,x,x) -> (x, x, x)
  • support postgres
  • create bug about parse params #4

Error JSON.parse(eventParams)

 index.ts: const params: any[] = JSON.parse(eventParams);

eventParams not always is json.
For example:

prisma.Movie.create({
    data: {
        description: `she will give him ten days of "love," at blabla....`,
    } 
})

Params in this case:

["she will give him ten days of "love," at blabla...."]

This is not valid json string.

Versions:

    "prisma": "^3.7.0",
    "prisma-query-log": "^3.1.0",

Error:

SyntaxError: Unexpected token l in JSON at position ...

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.