Insert
Simple Insert
SQL:
INSERT INTO films VALUES (?1, ?2, ?3, ?4, ?5, ?6)
Args:
"UA502"
"Bananas"
105
"1971-07-13"
"Comedy"
"82 mins"
Code:
sqlite.Insert(
im.Into("films"),
im.Values(sqlite.Arg("UA502", "Bananas", 105, "1971-07-13", "Comedy", "82 mins")),
)
Insert From Select
SQL:
INSERT INTO films SELECT * FROM tmp_films WHERE ("date_prod" < ?1)
Args:
"1971-07-13"
Code:
sqlite.Insert(
im.Into("films"),
im.Query(sqlite.Select(
sm.From("tmp_films"),
sm.Where(sqlite.Quote("date_prod").LT(sqlite.Arg("1971-07-13"))),
)),
)
Bulk Insert
SQL:
INSERT INTO films VALUES
(?1, ?2, ?3, ?4, ?5, ?6),
(?7, ?8, ?9, ?10, ?11, ?12)
Args:
"UA502"
"Bananas"
105
"1971-07-13"
"Comedy"
"82 mins"
"UA502"
"Bananas"
105
"1971-07-13"
"Comedy"
"82 mins"
Code:
sqlite.Insert(
im.Into("films"),
im.Values(sqlite.Arg("UA502", "Bananas", 105, "1971-07-13", "Comedy", "82 mins")),
im.Values(sqlite.Arg("UA502", "Bananas", 105, "1971-07-13", "Comedy", "82 mins")),
)
On Conflict Do Nothing
SQL:
INSERT INTO films VALUES (?1, ?2, ?3, ?4, ?5, ?6) ON CONFLICT DO NOTHING
Args:
"UA502"
"Bananas"
105
"1971-07-13"
"Comedy"
"82 mins"
Code:
sqlite.Insert(
im.Into("films"),
im.Values(sqlite.Arg("UA502", "Bananas", 105, "1971-07-13", "Comedy", "82 mins")),
im.OnConflict().DoNothing(),
)
Upsert
SQL:
INSERT INTO distributors AS "d" ("did", "dname")
VALUES (?1, ?2), (?3, ?4)
ON CONFLICT (did) DO UPDATE
SET "dname" = EXCLUDED. "dname"
WHERE ("d"."zipcode" <> '21201')
Args:
8
"Anvil Distribution"
9
"Sentry Distribution"
Code:
sqlite.Insert(
im.IntoAs("distributors", "d", "did", "dname"),
im.Values(sqlite.Arg(8, "Anvil Distribution")),
im.Values(sqlite.Arg(9, "Sentry Distribution")),
im.OnConflict("did").DoUpdate(
im.SetExcluded("dname"),
im.Where(sqlite.Quote("d", "zipcode").NE(sqlite.S("21201"))),
),
)
Or Replace
SQL:
INSERT OR REPLACE INTO distributors ("did", "dname")
VALUES (?1, ?2), (?3, ?4)
Args:
8
"Anvil Distribution"
9
"Sentry Distribution"
Code:
sqlite.Insert(
im.OrReplace(),
im.Into("distributors", "did", "dname"),
im.Values(sqlite.Arg(8, "Anvil Distribution")),
im.Values(sqlite.Arg(9, "Sentry Distribution")),
)