New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@142vip/data-source

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@142vip/data-source

通用型数据源,支持多种数据库、API、CSV等形式的数据源管理

latest
Source
npmnpm
Version
0.0.1-alpha.4
Version published
Maintainers
1
Created
Source

@142vip/data-source

NPM version

TIPS:没数据源,可视化、数字孪生就是玩单机

介绍

@142vip/data-source模块可以用来连接多种数据源,支持从数据源快速获取数据

安装

# npm
npm install @142vip/data-source
# pnpm
pnpm i @142vip/data-source

简单使用

按照数据来源,将数据源分为CSV型、API型、SQL数据库型三种类型。

新增数据源

定义接口类型

export interface MyDataSourceOptions {
  // coding xxx
}

初始化连接器

import { DataSourceConnector } from '@142vip/data-source'

export class MyDataSource implements DataSourceConnector<MyDataSourceOptions> {
  /**
   * 获取连接数据
   */
  public async getConnectionData(options: MyDataSourceOptions): Promise<DataSourceParseResponse> {
    try {
      // coding xxx
    }
    catch (error) {
      return handlerDataSourceConnectError(VipPostgreSql.name, error)
    }
    finally {
      await pgClient?.end()
    }
  }
}

进一步拓展

基于DataSourceManager接口,封装parseDatatestConnectgetDataBaseNames等常用方法。

/**
 * 自定义数据源
 */
export class MyDataSource implements DataSourceManager {
  /**
   * 解析数据
   */
  public async parseData(): Promise<DataSourceParseResponse> {
    // coding xxx
  }

  /**
   * 测试连接
   */
  public testConnect(): Promise<DataSourceParseResponse> {
    // coding xxx
  }

  /**
   * 获取表名列表
   */
  public getDataBaseNames(): Promise<DataSourceParseResponse<string[]>> {
    // coding xxx
  }

  /**
   * 获取表名列表
   */
  public getTableNames(): Promise<DataSourceParseResponse<DataSourceTable[]>> {
    // coding xxx
  }

  /**
   * 获取表字段列表
   */
  public getTableColumns(tableName: string, schema?: string): Promise<DataSourceParseResponse<DataSourceColumn[]>> {
    // coding xxx
  }
}

参考

证书

MIT

Copyright (c) 2019-present, @142vip 储凡

仅供学习参考,商业使用请保留作者版权信息,作者不保证也不承担任何软件的使用风险。

Keywords

公众号搜:储凡

FAQs

Package last updated on 25 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts