Originally shared by Andrea Raimondi

Originally shared by Andrea Raimondi

Russell Weetch and I are mulling the release of his company's data dictionary. This is, in essence, a very intuitive way to define tables and fields in code so that they can be generated in short order. 
It is quite useful as it does a number of things (such as letting you define a prefix at the table level and then apply it across the board to all fields, generating the needed SQL after comparing to the db, etc.) and it also has a number of other features. Do you think such a library would be interesting/useful for you?

Comments

  1. Gone for "I don't know, maybe, I have to see it" but that might change if an example is shown...

    ReplyDelete
  2. the data dictionary is a set of classes and Interfaces that enable you to define your data tables. The basic method is the RegisterFields(aTable, [array of Field Definitions]) method. If the table definition exists it will add the fields to that so, if like us you use objects, then the extra fields needed for descendants are defined with the descendants. you can register indexes and currently working on Views.

    The dictionary can be compared to a database and a sql script of the changes is generated. It uses FireDAC and also has a 'database type translation' interface to handle things that can be db specific. Currently there is one for Firebird.

    ReplyDelete
  3. If we didn't already have a tool for this, it would be exactly what we need :)

    At this point I doubt I'd get them to change anything. Good initiative though.

    ReplyDelete
  4. Something like?

      IDMField = interface
        function GetName : string;
        function GetDataType : TFieldType;
        function GetRealDataType: TFieldType;
        function GetSize: integer;
        function GetPrecision: integer;
        function GetDescription: string;
        function GetCalculated: string;
        function GetTable : IDMTable;
        function GetForeignKey : PDMForeignKey;
        function GetIsPrimary : boolean;

        property Name: string read GetName;
        property DataType: TFieldType read GetDataType;
        property RealDataType: TFieldType read GetRealDataType;
        property Size: integer read GetSize;
        property Precision: integer read GetPrecision;
        property Description: string read GetDescription;
        property Calculated: string read GetCalculated;
        property Table: IDMTable read GetTable;
        property ForeignKey: PDMForeignKey read GetForeignKey;
        property IsPrimaryKey: boolean read GetIsPrimary;
      end;

      IDMTable = interface
        function GetFields: TDMFieldDescList;
        function GetIndexes: TDMIndexDescList;
        function GetForeignKeys: TDMFKList;
        function GetName: string;
        function GetFullName: string;
        function GetDescription: string;
        function GetPrimaryKey: PDMIndex;
        function GetVersion: integer;

        function AddField(AVersion: integer; const AField: TDMField): IDMField;
        procedure AddIndex(AVersion: integer; const IndexFields: TDMFieldList; Flags: TDMIndexFlags = []; IndexName: string = '');
        procedure AddFK(AVersion: integer; const FKTable: IDMTable; const Fields, FKFields: TDMFieldList;
          OnUpdate: TFKAction = faCascade; OnDelete: TFKAction = faCascade);
        function FieldbyName(const FieldName: string): IDMField;
        property Fields: TDMFieldDescList read GetFields;
        property Indexes: TDMIndexDescList read GetIndexes;
        property ForeignKeys: TDMFKList read GetForeignKeys;
        property Name: string read GetName;
        property FillName: string read GetFullName;
        property Description: string read GetDescription;
        property PrimaryKey: PDMIndex read GetPrimaryKey;
        property Version: integer read GetVersion;
      end;

      TDMAdapter = class
      public
        Schema: TDMSchema;
        STDelimiter: string;
        function CreateUpdateScript(DBVersion: integer; const ASchema: TDMSchema): string; virtual;
        procedure ExecuteScript(const AScript: string); virtual; abstract;
        procedure CreateDatabase(const AName: string); virtual; abstract;
        procedure GetTableList(const L: TStrings); virtual; abstract;
        procedure GetTableFields(const TableName: string; const L: TStrings); virtual; abstract;
        procedure GetTableForeignKeys(const TableName: string; const L: TStrings); virtual; abstract;
        procedure GetTablePKFields(const TableName: string; const L: TStrings); virtual; abstract;
        procedure GetTableIndexes(const TableName: string; const L: TStrings); virtual; abstract;
        function TableSQL(const T: IDMTable): string; virtual;
        function ForeignKeySQL(const T: IDMTable; const FK: TDMForeignKey): string; virtual;
        function TableDiffSQL(const T: IDMTable): string; virtual;
        function FieldTypetoStr(FT: TFieldType; ASize, APrecision: integer): string; virtual;
      end;


      TDMSchema = class
      public
        constructor Create(const SchemaPrefix: string; const DBAdapter: TDMAdapter); virtual;
        function AddTable(const ATable: IDMTable): IDMTable; virtual;
        function TablebyName(const TableName: string): IDMTable;
        function CreateIndexName(const IndexFields: TDMFieldList; Flags: TDMIndexFlags): string; virtual;

    ReplyDelete
  5. function CreateFKName(const TableName, FKTableName: string; const IndexFields: TDMFieldList): string; virtual;
        function CreateGeneratorName(const Field: IDMField): string; virtual;
        property Prefix: string read fPrefix;
        property Tables: TDMTableList read fTables;
      end;

    ReplyDelete
  6. Alexander Sviridenkov is that on Git?

    ReplyDelete
  7. Russell Weetch  No, it is my internal unit. Also based on FD, but this dependency is isolated in  TDMAdapter class.

    ReplyDelete
  8. It's something along those lines, but I haven't abstracted the FireDac elements

    ReplyDelete
  9. Alexander Sviridenkov did you look at validating Views in your Schema?

    ReplyDelete
  10. Russell Weetch No, currently there is very basic implementation.

    ReplyDelete

Post a Comment