lightdash ProjectAdapter 接口定义
主要介绍接口定义,实际的实现后续说明
ProjectAdapter 是一个比较重要的东西,定义了project 以及dbt client ,WarehouseClient
接口定义
export interface ProjectAdapter {
compileAllExplores(): Promise<(Explore | ExploreError)[]>;
getDbtPackages(): Promise<DbtPackages | undefined>;
runQuery(sql: string): Promise<Record<string, any>[]>;
test(): Promise<void>;
destroy(): Promise<void>;
}
export interface DbtClient {
installDeps(): Promise<void>;
getDbtManifest(): Promise<DbtRpcGetManifestResults>;
getDbtCatalog(): Promise<DbtRpcDocsGenerateResults>;
getDbtPackages?(): Promise<DbtPackages | undefined>;
test(): Promise<void>;
}
export type WarehouseTableSchema = {
[column: string]: DimensionType;
};
export type WarehouseCatalog = {
[database: string]: {
[schema: string]: {
[table: string]: WarehouseTableSchema;
};
};
};
export interface WarehouseClient {
getCatalog: (
config: {
database: string;
schema: string;
table: string;
columns: string[];
}[],
) => Promise<WarehouseCatalog>;
runQuery(sql: string): Promise<Record<string, any>[]>;
test(): Promise<void>;
}
相关实现
packages/backend/src/projectAdapters/projectAdapter.ts
定义实现的入口,从此处也可以看出系统内部的实现
export const projectAdapterFromConfig = async (
config: DbtProjectConfig,
warehouseCredentials: CreateWarehouseCredentials,
): Promise<ProjectAdapter> => {
const warehouseClient =
warehouseClientFromCredentials(warehouseCredentials);
const configType = config.type;
Logger.debug(`Initialize project adaptor of type ${configType}`);
switch (config.type) {
case ProjectType.DBT:
return new DbtLocalCredentialsProjectAdapter({
warehouseClient,
projectDir: config.project_dir || '/usr/app/dbt',
warehouseCredentials,
});
case ProjectType.DBT_CLOUD_IDE:
return new DbtCloudIdeProjectAdapter({
warehouseClient,
accountId: `${config.account_id}`,
environmentId: `${config.environment_id}`,
projectId: `${config.project_id}`,
apiKey: config.api_key,
});
case ProjectType.GITHUB:
return new DbtGithubProjectAdapter({
warehouseClient,
githubPersonalAccessToken: config.personal_access_token,
githubRepository: config.repository,
githubBranch: config.branch,
projectDirectorySubPath: config.project_sub_path,
hostDomain: config.host_domain,
warehouseCredentials,
});
case ProjectType.GITLAB:
return new DbtGitlabProjectAdapter({
warehouseClient,
gitlabPersonalAccessToken: config.personal_access_token,
gitlabRepository: config.repository,
gitlabBranch: config.branch,
projectDirectorySubPath: config.project_sub_path,
hostDomain: config.host_domain,
warehouseCredentials,
});
case ProjectType.BITBUCKET:
return new DbtBitBucketProjectAdapter({
warehouseClient,
username: config.username,
personalAccessToken: config.personal_access_token,
repository: config.repository,
branch: config.branch,
projectDirectorySubPath: config.project_sub_path,
hostDomain: config.host_domain,
warehouseCredentials,
});
case ProjectType.AZURE_DEVOPS:
return new DbtAzureDevOpsProjectAdapter({
warehouseClient,
personalAccessToken: config.personal_access_token,
organization: config.organization,
project: config.project,
repository: config.repository,
branch: config.branch,
projectDirectorySubPath: config.project_sub_path,
warehouseCredentials,
});
default:
const never: never = config;
throw new Error(`Adapter not implemented for type: ${configType}`);
}
};
说明
ProjectAdapter 是比较重要的东西,当然lightdash内部还包含了其他东西,比如维度以及度量部分,有些是需要进行编译处理的,后续会介绍下
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2020-03-20 node-replay 一个很不错的nodejs api 录制以及回放包
2017-03-20 caddy server && caddyfile
2017-03-20 caddy server 默认https && http2的验证
2016-03-20 Windows Service Wrapper
2014-03-20 web开发的一些总结
2014-03-20 web 纯 javascript 的MVC 实现的简单实践