1. 快速向导
  2. 数据源

低代码平台的元数据驱动,使得跨数据库开发成为可能。基于低代码平台开发的软件包,理论上可以运行于不同的数据库架构上。

常见的数据源

通常需要支持以下类型的数据源:

  • SQL 数据库:MySQL, PostgreSQL, SQL Server, Oracle, …
  • NoSQL 数据库: MongoDB, Elastic Search, …
  • 大数据
  • OData API: 例如基于 OData 协议连接 Salesforce、SAP
  • 基于多租户需求,编写特定驱动。

跨数据库查询语法

为实现跨数据库架构,需要定义一套跨数据库的查询语法,详见 ObjectQL

数据源驱动

针对每一种数据库,需编写相应的数据源驱动。

驱动负责将 ObjectQL 语法转换为数据源可识别的语法,并与数据源交互。

数据源驱动还需要考虑数据库事务的执行。

驱动定义

定义一个数据源,通常需要实现以下函数:

export interface Driver {

    databaseVersion?: string;
    config?: SteedosDriverConfig;
    connect();
    close();
    getSupportedColumnTypes(): SteedosFieldDBType[];
    find(tableName: string, query: SteedosQueryOptions, userId?: SteedosIDType): any;
    aggregate?(tableName: string, query: SteedosQueryOptions, externalPipeline: any, userId?: SteedosIDType): any;
    findOne(tableName: string, id: SteedosIDType, query: SteedosQueryOptions, userId?: SteedosIDType): any;
    insert(tableName: string, doc: Dictionary<any>, userId?: SteedosIDType): any;
    insertMany?(tableName: string, docs: Dictionary<any>[], userId?: SteedosIDType): any;
    update(tableName: string, id: SteedosIDType | SteedosQueryOptions, doc: Dictionary<any>, userId?: SteedosIDType): any;
    updateOne(tableName: string, id: SteedosIDType | SteedosQueryOptions, doc: Dictionary<any>, userId?: SteedosIDType): any;
    updateMany?(tableName: string, queryFilters: SteedosQueryFilters, doc: Dictionary<any>, userId?: SteedosIDType): any;
    delete(tableName: string, id: SteedosIDType | SteedosQueryOptions, userId?: SteedosIDType): any;
    deleteMany?(tableName: string, queryFilters: SteedosQueryFilters, userId?: SteedosIDType): any;
    directUpdate(tableName: string, id: SteedosIDType | SteedosQueryOptions, doc: Dictionary<any>, userId?: SteedosIDType): any;
    directUpdateMany?(tableName: string, queryFilters: SteedosQueryFilters, doc: Dictionary<any>, userId?: SteedosIDType): any;
    directFind(tableName: string, query: SteedosQueryOptions, userId?: SteedosIDType): any;
    directInsert(tableName: string, doc: Dictionary<any>, userId?: SteedosIDType): any;
    directInsertMany?(tableName: string, docs: Dictionary<any>[], userId?: SteedosIDType): any;
    directDelete(tableName: string, id: SteedosIDType | SteedosQueryOptions, userId?: SteedosIDType): any;
    directDeleteMany?(tableName: string, queryFilters: SteedosQueryFilters, userId?: SteedosIDType): any;
    directAggregate?(tableName: string, query: SteedosQueryOptions, externalPipeline: any, userId?: SteedosIDType): any;
    directAggregatePrefixalPipeline?(tableName: string, query: SteedosQueryOptions, prefixalPipeline: any, userId?: SteedosIDType): any;
    count(tableName: string, query: SteedosQueryOptions, userId?: SteedosIDType): any;
    dropEntities?(): any;
    registerEntities?(objects: Dictionary<SteedosObjectType>): any;
    dropTables?(): any;
    createTables?(objects: Dictionary<SteedosObjectType>): any;
    init(objects: Dictionary<SteedosObjectType>): any;
    _makeNewID?(tableName?: string): any
}

驱动注册

平台需提供数据源驱动注册入口,可通过编写插件的形式扩展数据源驱动。