Project Description
Sqlite ORM is a simple C# Class to Table mapper for Sqlite databases.
Tables are created on demand, and designed for Sharding.
Code has 100% unit test coverage.

Why?
Rapid Application Development. Write your code first, POCO with attributes. Then use table adapters for CRUD (create read update delete). SqliteORM does the rest, including table creation.

If you understand this piece of code, you probably get just how easy this SqliteORM is.
var myClass = new MyClass() { Name = "Foo", Date = DateTime.Now };
myClass.Save(); 

Longer Example
This example defines an entity "SimpleTable".
It creates a table "SimpleTable" and writes ( 1, "Hello world!" ) into it.
Then look up the record where Id = 1
Updates the record to "Cheese"
Then deletes that record.

[Table]
public class SimpleTable 
{
    [PrimaryKey]    public int Id { get; set; }
    [Field]         public string Test { get; set; }
}

     DbConnection.Initialise("data source=database.db3");

     using (TableAdapter<SimpleTable > adapter = TableAdapter<SimpleTable >.Open())
     {
              // Create
              adapter.CreateUpdate( 1, "Hello world!" );

              // Read
              var row = adapter.Select().Where( tb => tb.Id == 1 );
              
              // Update
              row.Test = "Cheese";
              adapter.CreateUpdate( row );
              
              // Delete
              adapter.Delete( row1 );
     } 


Select results using Fluent Syntax API with .Where( expression ) and .OrderBy( field ).
Example: var results = adapter.Select().Where( tbl => tbl.Value > 100 && tbl.When <= DateTime.Now )
or var results = adapter.Select().Where( Where.Equal("Value", 99) )

Delete
Using a Where adapter.Delete( Where.GreaterThan ( "SomeField", 23 ) );

Anonymous Tables
Access data from a table where you don't have a C# class definition.
using (AnonymousAdapter adapter = AnonymousAdapter.Open("SimpleTable")) {
   var row = adapater.Select().Where( Where.Equal( "Id", 10 ));
   Console.WriteLine("Id: {0} Test: {1}", row["Id"], row["Test"] ); 


JOIN
Source code now includes JOIN via Mash class. (No support for left joins etc)
 using (var adapater = TableAdapter<Mash<Role, RolePermissions, Permission>>.Open())
            {
                foreach (var mashObj in adapater.Select())
                {
                    var mash = (Mash<Role, RolePermissions, Permission>)mashObj;
                    Console.WriteLine( "{0}\t{1}", mash.Table1.Name, mash.Table3.Name );
                }


Transactions
using (DbTransaction tran = DbTransaction.Open())
{
    simple = new SimpleTable() { Id = 9, Test = "Hello" };
    simple.Save();
    tran.Commit();   
} 

Last edited Nov 9, 2012 at 4:01 PM by DarkStranger, version 21