Esempio n. 1
0
        public StringBuilder WriteQuery()
        {
            StringBuilder queryBuilder = new StringBuilder($"UPDATE {KeyspaceName}.{TableName}");

            if (UpdateParameters != null &&
                UpdateParameters.Count > 0)
            {
                queryBuilder.AppendLine();
                queryBuilder.Append("USING ");

                bool first = true;

                foreach (UpdateParameter parameter in UpdateParameters)
                {
                    if (!first)
                    {
                        queryBuilder.Append(" AND ");
                    }
                    else
                    {
                        first = false;
                    }

                    parameter.WriteCql(queryBuilder);
                }
            }

            if (Assignments != null &&
                Assignments.Count > 0)
            {
                queryBuilder.AppendLine();
                queryBuilder.Append("SET ");

                bool first = true;

                foreach (Assignment assignment in Assignments)
                {
                    if (!first)
                    {
                        queryBuilder.Append(", ");
                    }
                    else
                    {
                        first = false;
                    }

                    assignment.WriteCql(queryBuilder);
                }
            }

            if (WhereClause != null)
            {
                queryBuilder.AppendLine();
                WhereClause.WriteCql(queryBuilder);
            }

            if (Conditions != null &&
                Conditions.Count > 0)
            {
                queryBuilder.AppendLine();
                queryBuilder.Append("IF ");

                bool first = false;

                foreach (Condition condition in Conditions)
                {
                    if (!first)
                    {
                        queryBuilder.Append(" AND ");
                    }
                    else
                    {
                        first = false;
                    }

                    condition.WriteCql(queryBuilder);
                }
            }
            else if (IfExists)
            {
                queryBuilder.AppendLine();
                queryBuilder.Append("IF EXISTS");
            }

            queryBuilder.Append(";");
            return(queryBuilder);
        }
Esempio n. 2
0
        public StringBuilder WriteQuery()
        {
            StringBuilder queryBuilder = new StringBuilder("SELECT ");

            if (Json)
            {
                queryBuilder.Append("JSON ");
            }
            else if (Distinct)
            {
                queryBuilder.Append("DISTINCT ");
            }

            if (SelectClause == null)
            {
                queryBuilder.Append("*");
            }
            else
            {
                SelectClause.WriteCql(queryBuilder);
            }

            queryBuilder.AppendLine();
            queryBuilder.Append($"FROM ");

            if (KeyspaceName == null)
            {
                queryBuilder.Append(TableName);
            }
            else
            {
                queryBuilder.Append($"{KeyspaceName}.{TableName}");
            }

            if (WhereClause != null)
            {
                queryBuilder.AppendLine();
                WhereClause.WriteCql(queryBuilder);
            }

            if (GroupingClause != null &&
                GroupingClause.FieldNames != null &&
                GroupingClause.FieldNames.Count() > 0)
            {
                queryBuilder.AppendLine();
                GroupingClause.WriteCql(queryBuilder);
            }

            if (OrderingClause != null &&
                OrderingClause.Orders != null &&
                OrderingClause.Orders.Count() > 0)
            {
                queryBuilder.AppendLine();
                OrderingClause.WriteCql(queryBuilder);
            }

            if (PerPartitionLimit != null)
            {
                queryBuilder.AppendLine();
                queryBuilder.Append("PER PARTITION LIMIT ");
                PerPartitionLimit.WriteCql(queryBuilder);
            }

            if (Limit != null)
            {
                queryBuilder.AppendLine();
                queryBuilder.Append("LIMIT ");
                Limit.WriteCql(queryBuilder);
            }

            if (AllowFiltering)
            {
                queryBuilder.AppendLine();
                queryBuilder.Append("ALLOW FILTERING");
            }

            queryBuilder.Append(";");

            return(queryBuilder);
        }