-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support cockroach db * Update comment
- Loading branch information
Showing
13 changed files
with
274 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2020-2022 OnFinality Limited authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {SUPPORT_DB} from '@subql/common'; | ||
import {Pool} from 'pg'; | ||
import {Sequelize} from 'sequelize'; | ||
|
||
export async function getDbType(queryFrom: Sequelize | Pool): Promise<SUPPORT_DB> { | ||
const result = await (queryFrom as any).query('select version()'); | ||
// sequelize return an array, Promise<[unknown[], unknown] | ||
// pgPool return a single string object with rows | ||
const cleanResult = result instanceof Array ? result[0][0] : result.rows[0]; | ||
const matchDB = Object.values(SUPPORT_DB).find((db) => (cleanResult as {version: string}).version.includes(db)); | ||
if (!matchDB) { | ||
throw new Error(`Database type not supported, got ${result}`); | ||
} | ||
return matchDB; | ||
} |
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 @@ | ||
// Copyright 2020-2022 OnFinality Limited authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './databaseUtil'; |
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,11 @@ | ||
version: '3.5' | ||
|
||
services: | ||
crdb: | ||
image: cockroachdb/cockroach:latest-v22.1 | ||
ports: | ||
- '26257:26257' | ||
- '8080:8080' | ||
command: start-single-node --insecure | ||
volumes: | ||
- '${PWD}/cockroach-data/crdb:/cockroach/cockroach-data' |
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
Oops, something went wrong.