Introduction of SQLite

SQLite is a lightweight, server-less database, it's great for embedding into client application. It works across Windows, iOS, Android, browers. 

 

Code snippets 

Create database connection

var connection = new SQLiteAsyncConnection("testdb.sqlite");

Create table

await connection.CreateTableAync<MyClass>();

Insert Data

await connection.InsertAsync(new MyClass());

Build up your class

public class MyClass

{

  [PrimaryKey]

  public string Id { get; set; }

  public DateTime CreatedOn { get; set; }

  public string Name { get; set; }

  [Ignore]

  public ComplexClass IgnoreMe { get; set; }

}

Querying

var items = connection.Table<MyClass>()

            .Where(x=>x.Name == "Bob")

            .FirstOrDefault();

Starting off

var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("Assets\\dbfile.sqlite");

try

{

  await file.CopyAsync(ApplicationData.Current.LocalFolder);

}

catch

{

}

 

sqlite:

http://www.sqlite.org/

sqlite-net:

https://github.com/praeclarum/sqlite-net

sqlite-net-wp8:

https://github.com/peterhuene/sqlite-net-wp8

Sample:

http://bit.ly/TLWrZw

 

 

posted @ 2013-10-05 10:36  MinieGoGo  阅读(232)  评论(0编辑  收藏  举报