EaToSql


EA to SQL

This utility converts an Enterprise Architect (EA) XMI data model export into a SQL create script for SQL Server.

Example

Converting a simple data model to SQL, define the tables like this:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
#r "EaToSql.dll"
open EaToSql

let model = 
    [ table "t1" [ col "id" IntAuto ]
      { table "t2" [ col "t2id" IntAuto ]
            with Indexes = [ ix [ "id" ] ]
                 Relationships = [ rel ["id"] (target "t1" ["id"]) ]
      }
      { table "t3" [ col "first" (NVarChar 100)
                     col "last" (NVarChar 100) ]
            with Indexes = [ ix [ "first" ]
                             ix [ "last" ]
                             ix [ "first"; "last" ] ]
      }]

Next, generate SQL statements like this:

1: 
model |> generateSqlFromModel |> Seq.toArray

The output is:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
val it : string [] =
  [|"CREATE TABLE [t1] (id int NOT NULL IDENTITY(1,1)";
    "CONSTRAINT [pk_t1_id] PRIMARY KEY CLUSTERED (id))";
    "CREATE TABLE [t2] (t2id int NOT NULL IDENTITY(1,1)";
    "CONSTRAINT [pk_t2_t2id] PRIMARY KEY CLUSTERED (t2id))";
    "CREATE INDEX [ix_t2_id] ON [t2] (id)";
    "CREATE TABLE [t3] (first nvarchar(100) NOT NULL, last nvarchar(100) NOT NULL";
    "CONSTRAINT [pk_t3_first] PRIMARY KEY CLUSTERED (first))";
    "CREATE INDEX [ix_t3_first] ON [t3] (first)";
    "CREATE INDEX [ix_t3_last] ON [t3] (last)";
    "CREATE INDEX [ix_t3_first_last] ON [t3] (first, last)";
    "ALTER TABLE [t2] ADD CONSTRAINT [fk_t2_t1] FOREIGN KEY (id) REFERENCES [t1] (id)"|]

Samples & documentation

The API reference is automatically generated from Markdown comments in the library implementation.

  • Tutorial contains a further explanation of this sample library.

  • API Reference contains automatically generated documentation for all types, modules and functions in the library. This includes additional brief samples on using most of the functions.

Contributing and copyright

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. If you're adding a new public API, please also consider adding samples that can be turned into a documentation. You might also want to read the library design notes to understand how it works.

The library is available under Public Domain license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.

namespace EaToSql
val model : Table list

Full name: Index.model
val table : name:ModelName -> cols:ColumnDef list -> Table

Full name: EaToSql.Dsl.table
val col : name:ModelName -> dtype:DataType -> ColumnDef

Full name: EaToSql.Dsl.col
union case DataType.IntAuto: DataType
val ix : cols:ColumnRef list -> Index

Full name: EaToSql.Dsl.ix
val rel : srcCols:ColumnRef list -> target:RelTarget -> Relationship

Full name: EaToSql.Dsl.rel
val target : tname:ModelName -> cols:ColumnRef list -> RelTarget

Full name: EaToSql.Dsl.target
union case DataType.NVarChar: length: int -> DataType
val generateSqlFromModel : (seq<Table> -> seq<string>)

Full name: EaToSql.Api.generateSqlFromModel
module Seq

from Microsoft.FSharp.Collections
val toArray : source:seq<'T> -> 'T []

Full name: Microsoft.FSharp.Collections.Seq.toArray
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
Fork me on GitHub