-
Notifications
You must be signed in to change notification settings - Fork 0
Example.QueryBuilder.Insert
IzayoiJiichan edited this page Aug 14, 2024
·
1 revision
{
var queryOption = new QueryOption();
var queryBuilder = new QueryBuilder(queryOption);
var insert1 = new Insert();
insert1.SetInto("users")
.Values
.Add("id", 1)
.Add("name", "name1")
.Add("age", 20)
.Add("created_at", DateTimeOffset.UtcNow)
.Add("updated_at", DateTimeOffset.UtcNow);
queryBuilder.Build(insert1);
string query = queryBuilder.GetQuery();
var parameters = queryBuilder.GetParameters();
// query:
// INSERT INTO users
// (id, name, age, created_at, updated_at)
// VALUES
// (@v_0, @v_1, @v_2, @v_3, @v_4)
// parameters:
// [0]:
// ParameterName: @v_0
// DbType: DbType.Int32
// Value: 1
// [1]:
// ParameterName: @v_1
// DbType: DbType.String
// Value: "name1"
// [2]:
// ParameterName: @v_2
// DbType: DbType.Int32
// Value: 20
// [3]:
// ParameterName: @v_3
// DbType: DbType.DateTime
// Value: (2024-08-01 00:00:00)
// [4]:
// ParameterName: @v_4
// DbType: DbType.DateTime
// Value: (2024-08-01 00:00:00)
}
{
var insert2 = new Insert();
insert2.SetInto("users")
.Select ??= new Select()
.SetFrom("users2")
.AddField("id")
.AddField("name")
.AddField("age")
.AddField("created_at")
.AddField("updated_at");
// query:
// INSERT INTO users
// SELECT id, name, age, created_at, updated_at
// FROM users2
}
- Izayoi.Data
- Izayoi.Data.Query
- Izayoi.Data.Repository
- Izayoi.Data.Validation
Examples