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.
Full name: Index.model
Full name: EaToSql.Dsl.table
Full name: EaToSql.Dsl.col
Full name: EaToSql.Dsl.ix
Full name: EaToSql.Dsl.rel
Full name: EaToSql.Dsl.target
Full name: EaToSql.Api.generateSqlFromModel
from Microsoft.FSharp.Collections
Full name: Microsoft.FSharp.Collections.Seq.toArray
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string