-
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.
Merge pull request #175 from migalabs/feat-migration-clickhouse
Migration Database to Clickhouse
- Loading branch information
Showing
23 changed files
with
1,190 additions
and
862 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
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,4 @@ | ||
DB_USER= | ||
DB_HOST= | ||
DB_NAME= | ||
DB_PASSWORD= |
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,60 @@ | ||
import { createClient } from '@clickhouse/client'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const client = createClient({ | ||
host: process.env.DB_HOST, | ||
username: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
}); | ||
|
||
interface Table { | ||
name: string; | ||
} | ||
|
||
interface Column { | ||
name: string; | ||
type: string; | ||
} | ||
|
||
const fetchTables = async (): Promise<Table[]> => { | ||
|
||
const resultSet = await client.query({ | ||
query: 'SHOW TABLES', | ||
format: 'JSONEachRow', | ||
}); | ||
|
||
return resultSet.json(); | ||
} | ||
|
||
const fetchColumns = async (table: string): Promise<Column[]> => { | ||
|
||
const resultSet = await client.query({ | ||
query: `DESCRIBE ${table}`, | ||
format: 'JSONEachRow', | ||
}); | ||
|
||
return resultSet.json(); | ||
} | ||
|
||
const printSchema = async () => { | ||
|
||
const tables = await fetchTables(); | ||
|
||
console.log('Database Schema:\n'); | ||
|
||
for (const table of tables) { | ||
|
||
console.log(`- ${table.name}`); | ||
|
||
const columns = await fetchColumns(table.name); | ||
|
||
for (const column of columns) { | ||
console.log(` - ${column.name} (${column.type})`); | ||
} | ||
} | ||
}; | ||
|
||
printSchema(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,22 @@ | ||
{ | ||
"name": "clickhouse-overviewer", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "npx tsc", | ||
"start": "node dist/app.js", | ||
"launch": "npm run build && npm start" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/node": "^20.12.7", | ||
"typescript": "^5.4.5" | ||
}, | ||
"dependencies": { | ||
"@clickhouse/client": "^0.2.10", | ||
"dotenv": "^16.4.5" | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"target": "es6", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "dist", | ||
}, | ||
"lib": ["es2015"] | ||
} |
Oops, something went wrong.