-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
194 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
quote_type = single |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"root": true, | ||
"extends": [ | ||
"@autotelic/eslint-config-js" | ||
], | ||
"settings": { | ||
"node": { | ||
"version": "^18.x" | ||
} | ||
}, | ||
"overrides": [{ | ||
"files": ["*.ts"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"] | ||
}], | ||
"rules": { | ||
"multiline-comment-style": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Validate & Release | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
jobs: | ||
validate: | ||
uses: ./.github/workflows/validate.yaml | ||
|
||
publish-npm: | ||
runs-on: ubuntu-latest | ||
needs: validate | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: .node-version | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Lint & Test | ||
|
||
on: | ||
workflow_call: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
validate: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: .node-version | ||
registry-url: 'https://registry.npmjs.org' | ||
- run: npm install | ||
- run: npm run validate |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
16.15.1 | ||
18.19.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
const pg = require('pg') | ||
const QueryStream = require('pg-query-stream') | ||
|
||
const { fastifyStreamToCsv } = require('../../') | ||
|
||
const connectionString = 'postgres://postgres:[email protected]:5432/postgres?sslmode=disable' | ||
|
||
module.exports = async function (fastify, options) { | ||
module.exports = async function csv (fastify, options) { | ||
fastify.register(fastifyStreamToCsv) | ||
|
||
fastify.get('/db-report', async function (req, reply) { | ||
fastify.get('/db-report', async function report (req, reply) { | ||
// create a readable stream | ||
const stream = new QueryStream('SELECT * FROM generate_series(0, $1) num', [10000]) | ||
const client = new pg.Client({ connectionString }) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Readable } from 'stream' | ||
|
||
import { FormatterOptionsArgs } from '@fast-csv/format' | ||
import type { FastifyPluginCallback } from 'fastify' | ||
|
||
export interface StreamToCsvOptions { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
csvOptions?: FormatterOptionsArgs<any, any> | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type RowFormatterFunction = (row: any) => any[] | ||
|
||
declare module 'fastify' { | ||
interface FastifyReply { | ||
streamToCsv( | ||
readStream: Readable, | ||
rowFormatter: RowFormatterFunction, | ||
options?: StreamToCsvOptions | ||
): void | ||
} | ||
} | ||
|
||
declare const fastifyStreamToCsv: FastifyPluginCallback<StreamToCsvOptions> | ||
|
||
export default fastifyStreamToCsv | ||
export { fastifyStreamToCsv } |
Oops, something went wrong.