PetaPoco icon indicating copy to clipboard operation
PetaPoco copied to clipboard

Using Sql.Builder with fields list or with dictionary of the predetermined values

Open QuAzI opened this issue 10 years ago • 0 comments

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

QuAzI avatar Apr 26 '15 12:04 QuAzI