DotNetWorkQueue.Transport.PostgreSQL.Schema.Table.Script C# (CSharp) Method

Script() public method

Translates this table into a SQL script
public Script ( ) : string
return string
		public string Script() 
        {
			var text = new StringBuilder();
			text.AppendFormat("CREATE TABLE {0} (\r\n", Name);
			text.Append(Columns.Script());
            if (Constraints.Count > 0)
            {
                text.AppendLine();
            }
            //add anything that is not an index
			foreach (var c in Constraints.Where(c => c.Type != ContraintType.Index))
			{
			    text.AppendLine("   ," + c.Script());
			}
			text.AppendLine();
            text.AppendLine(");");
            //add indexes
            foreach (var c in Constraints.Where(c => c.Type == ContraintType.Index))
			{
			    text.AppendLine(c.Script());
                text.AppendLine(";");
            }
			return text.ToString();
        }
        #endregion

Usage Example

Beispiel #1
0
 public void Create_Script()
 {
     var c = new Column("testing", ColumnTypes.Bigint, true);
     var cc = new Constraint("ix_testing", ContraintType.Index, "testing");
     var test = new Table("test");
     test.Constraints.Add(cc);
     test.Columns.Add(c);
     //set the table reference
     foreach (var ccc in test.Constraints)
     {
         ccc.Table = test.Info;
     }
     Assert.Contains("test", test.Script());
 }