import setupLogger from '@/config/logger' ; import { IExplorer } from '@/services/datastores/base/datastore' ; import { ICassandraAccessDef , IClusterSchemaColumn , ICreateTableOptions , IDatacenter , IKeyResult , IKeyspace , IKeyspaceReplication , IStatementResult , ITableSchema , ITableSummary , IUserDefinedType , IClusterInfo , IKeyQuery , CassEncoding , IRowDetails , IStatementExecuteOptions , } from '@/services/datastores/cassandra/typings/cassandra' ; import { Client } from 'cassandra-driver' ; import { getBinaryValue } from './modules/blob' ; import { getClusterSchema } from './modules/columns' ; import { deleteKey , generateInsertStatement , getKeys , insertKey , updateKey , } from './modules/keys' ; import { getKeyspace , getKeyspaces } from './modules/keyspaces' ; import { createKeyspace , createTable , createTableAdvanced , dropTable , generateCreateStatement , truncateTable , } from './modules/schema' ; import { execute } from './modules/statement' ; import { getTable , getTables } from './modules/tables' ; import { getTypes } from './modules/types' ; import { getVersion } from './utils/cluster-utils' ; const logger = setupLogger ( module ) ; export default class CassandraExplorer implements IExplorer { param client constructor ( readonly client ) { } returns public async getDatacenters ( ) { logger . info ( 'fetching cluster regions' ) ; await this . client . connect ( ) ; const datacenters = this . client . metadata . datacenters ; return Object . keys ( datacenters ) . sort ( ) . map ( ( datacenter ) => ( { name : datacenter , racks : datacenters [ datacenter ] . racks . toArray ( ) , } ) ) ; } param keyspaceName param datacenters returns public async createKeyspace ( keyspaceName , datacenters ) { return createKeyspace ( this . client , keyspaceName , datacenters ) ; } param keyspaceName param tableName public async dropTable ( keyspaceName , tableName ) { return dropTable ( this . client , keyspaceName , tableName ) ; } param keyspaceName param tableName public async truncateTable ( keyspaceName , tableName ) { return truncateTable ( this . client , keyspaceName , tableName ) ; } param tableOptions return public async generateCreateStatement ( tableOptions ) { return generateCreateStatement ( this . client , tableOptions ) ; } param options return public async createTable ( options , clusterAcccess ) { return createTable ( this . client , options , clusterAcccess ) ; } param options return public async createTableAdvanced ( keyspace , table , createStatement , clusterAcccess ) { return createTableAdvanced ( this . client , keyspace , table , createStatement , clusterAcccess ) ; } public async getClusterInfo ( ) { return { version : getVersion ( this . client ) , } ; } returns public async getKeyspaces ( ) { return getKeyspaces ( this . client ) ; } param keyspaceName returns public async getKeyspace ( keyspaceName ) { return getKeyspace ( this . client , keyspaceName ) ; } param keyspace returns public async getTables ( keyspace ) { return getTables ( this . client , keyspace ) ; } param keyspace returns public async getClusterSchema ( keyspace ? ) { return getClusterSchema ( this . client , keyspace ) ; } param keyspace param table returns public async getTable ( keyspace , table ) { return getTable ( this . client , keyspace , table ) ; } param keyspaceName return { Promise . < { standard : Array . < * > , user } > } public async getTypes ( keyspaceName ) { return getTypes ( this . client , keyspaceName ) ; } param query param clusterAccess param logMetadata returns public async execute ( query , clusterAccess , logMetadata , options ? ) { return execute ( this . client , query , clusterAccess , logMetadata , options ) ; } param { String } keyspace param { String } table param { Object } params param { String } pageState param { Object } logMetadata returns { Promise . < TResult > | * } public async getKeys ( keyspace , table , params , pageState , logMetadata ) { return getKeys ( this . client , keyspace , table , params , pageState , logMetadata ) ; } public generateInsertStatement ( schema , fields , encoding ) { return generateInsertStatement ( schema , fields , encoding ) ; } public async getBinaryValue ( keyspace , table , keyQuery , binaryColumnName ) { return getBinaryValue ( this . client , keyspace , table , keyQuery , binaryColumnName ) ; } param keyspace param table param key param updateFields param logMetadata returns public async updateKey ( keyspace , table , key , updateFields , logMetadata ) { return updateKey ( this . client , keyspace , table , key , updateFields , logMetadata ) ; } param keyspace param table param fields param logMetadata public async insertKey ( keyspace , table , row , logMetadata ) { return insertKey ( this . client , keyspace , table , row , logMetadata ) ; } param keyspace param table param key param logMetadata return public async deleteKey ( keyspace , table , key , logMetadata ) { return deleteKey ( this . client , keyspace , table , key , logMetadata ) ; } public shutdown ( ) { return this . client . shutdown ( ) ; } }