PetaPoco
PetaPoco copied to clipboard
Using Sql.Builder with fields list or with dictionary of the predetermined values
I want to fill only initialized fields in a convenient form. May I write something like it
var fields = new Dictionary<string, string>()
{
{ "name", "tequila" },
{ "price", "42" },
{ "photo", "tequila.jpg" }
};
var sql=PetaPoco.Sql.Builder()
.Insert(fields)
.To('drinks')
To build query which is equivalent to the next query
INSERT INTO
`drinks`
SET
`name` = 'tequila',
`price` = 42,
`photo` = 'tequila.jpg'
Or something like this:
var fields = new string[] { "name", "price", "photo" };
var tables = new string[] { "drinks", "drinks_photos" };
var sql=PetaPoco.Sql.Builder()
.Select(fields)
.From(tables)
.Where("drinks.id = drinks_id")
.OrderBy("drinks_id");
to build
SELECT name, price, photo
FROM drinks, drinks_photos
WHERE drinks.id = drinks_id
ORDER BY drinks_id