praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
4.03k stars 1.42k forks source link

Implemented Fluent Api based on @RoyGoode's code #1220

Closed lancecontreras closed 5 months ago

lancecontreras commented 6 months ago

I have noticed that there's been a few attempt to implement fluent api for sqlite-net in the past. The prominent one being from @RoyGoode.

This is my attempt to implement fluent API that is based on @RoyGoode's code. I also took to consideration the author's (@praeclarum) comment in #533. This should get rid of the requirement to use the attribute for table and columns.

Usage

    var mapping = TableMapping.Builder<SomeTable>()
        .TableName("some_table")
        .ColumnName(s => s.Name, "some_name")
        .AutoIncrement(s => s.MyId)
        .PrimaryKey(s => s.MyId)
        .Unique(s => s.MyId)
    .Build();

    connection.UseMapping(mapping);
    connection.CreateTable<SomeTable>();

    // or 

   connection.CreateTable<SomeTable>(mapping); 

   // this also supports CreateTables(map1, map2, map3, ... ); 

I'm open to any comments and suggestions.