示例#1
0
        /// <summary>
        /// Add a new string constant to the generated type
        /// </summary>
        /// <param name="generatedType"></param>
        /// <param name="constantName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Setter AddStringConstant(this GeneratedType generatedType, string constantName, string value)
        {
            var setter = Setter.Constant(constantName, Constant.ForString(value));

            generatedType.Setters.Add(setter);

            return(setter);
        }
示例#2
0
        public GeneratedType Build(GeneratedAssembly assembly)
        {
            var baseType = typeof(DeleteOne <,>).MakeGenericType(_mapping.DocumentType, _mapping.IdType);
            var type     = assembly.AddType($"Delete{_mapping.DocumentType.Name.Sanitize()}ById", baseType);

            var sql = $"delete from {_mapping.Table.QualifiedName} as d where id = ?";

            if (_mapping.DeleteStyle == DeleteStyle.SoftDelete)
            {
                sql =
                    $"update {_mapping.Table.QualifiedName} as d set {DocumentMapping.DeletedColumn} = True, {DocumentMapping.DeletedAtColumn} = now() where id = ?";
            }

            if (_mapping.TenancyStyle == TenancyStyle.Conjoined)
            {
                sql += $" and d.{TenantIdColumn.Name} = ?";
            }


            var commandText = Setter.Constant("CommandText", Constant.For(sql));

            type.Setters.Add(commandText);

            var configure = type.MethodFor(nameof(IQueryHandler.ConfigureCommand));

            configure.Frames.Call <CommandBuilder>(x => x.AppendWithParameters(null), call =>
            {
                call.Arguments[0] = commandText;
            });

            // Add the Id parameter
            configure.Frames.Code(@"
// Id parameter
{0}[0].NpgsqlDbType = {1};
{0}[0].Value = {2};

", Use.Type <NpgsqlParameter[]>(), TypeMappings.ToDbType(_mapping.IdType), type.AllInjectedFields[0]);

            if (_mapping.TenancyStyle == TenancyStyle.Conjoined)
            {
                configure.Frames.Code($@"
// tenant
{{0}}[1].NpgsqlDbType = {{1}};
{{0}}[1].Value = {{2}}.{nameof(IMartenSession.Tenant)}.{nameof(ITenant.TenantId)};
", Use.Type <NpgsqlParameter[]>(), NpgsqlDbType.Varchar, Use.Type <IMartenSession>());
            }


            return(type);
        }
示例#3
0
        public void const_with_initial_value_of_variable_using_enum()
        {
            var setter = Setter.Constant("Color", Constant.ForEnum(Color.red));

            setter.ToDeclaration().ShouldBe("public const LamarCompiler.Testing.Codegen.Color Color = LamarCompiler.Testing.Codegen.Color.red;");
        }
示例#4
0
        public void const_with_initial_value_of_variable()
        {
            var setter = Setter.Constant("Color", Constant.ForString("red"));

            setter.ToDeclaration().ShouldBe("public const string Color = \"red\";");
        }