/// <summary>
        /// Extract PrimaryKey Definition from context
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static MySqlKeyDefinition ExtractPrimaryKey(PrimaryKeyTableConstraintContext context)
        {
            if (context == null)
            {
                throw new ArgumentOutOfRangeException($"{nameof(context)} is null");
            }

            var keys   = context.GetIndexNames();
            var pkName = context.GetChildlen <IndexColumnNamesContext>()
                         .Single()
                         .GetText().RemoveBackQuote().RemoveParenthesis();
            var pkIndexes  = keys.Select(x => x.RemoveBackQuote().RemoveParenthesis()).ToArray();
            var definition = new MySqlKeyDefinition
            {
                KeyName = pkName,
                Indexes = pkIndexes.Select((x, i) => new MySqlKeyDetailDefinition
                {
                    Order    = i,
                    IndexKey = x,
                })
                          .ToArray(),
            };

            return(definition);
        }
 public void AddUniqueKey(MySqlKeyDefinition index)
 {
     if (IndexKeys == null)
     {
         UniqueKeys = new HashSet <MySqlKeyDefinition>();
     }
     UniqueKeys.Add(index);
 }
 public void AddIndexKeysReference(MySqlKeyDefinition index)
 {
     if (IndexKeysReferences == null)
     {
         IndexKeysReferences = new HashSet <MySqlKeyDefinition>();
     }
     IndexKeysReferences.Add(index);
 }
 public void AddUniqueKeysReference(MySqlKeyDefinition index)
 {
     if (UniqueKeysReferences == null)
     {
         UniqueKeysReferences = new HashSet <MySqlKeyDefinition>();
     }
     UniqueKeysReferences.Add(index);
 }
        /// <summary>
        /// Extract Key Definition from context
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private static MySqlKeyDefinition ExtractKeyDefinition(ParserRuleContext context)
        {
            var indexName = context.GetChild <UidContext>().GetText();
            var indexes   = context.GetChild <IndexColumnNamesContext>();
            var indexData = Enumerable.Range(0, indexes.ChildCount)
                            .Select(x => indexes.GetChild(x) is IndexColumnNameContext columnName
                    ? columnName.GetText()
                    : "")
                            .Where(x => !string.IsNullOrEmpty(x))
                            .Select((x, i) => new MySqlKeyDetailDefinition
            {
                IndexKey = x.RemoveBackQuote(),
                Order    = i,
            })
                            .ToArray();

            var definition = new MySqlKeyDefinition()
            {
                KeyName = indexName.RemoveBackQuote(),
                Indexes = indexData,
            };

            return(definition);
        }