public void QuerySingleUser() { IConnection connection = Program.GetOpenConnection(); if (!connection.ExistTable<User>()) connection.CreateTable<User>(); User user1 = new User { username = "******", password = "******" }; User user2 = new User { username = "******", password = "******" }; User user3 = new User { username = "******", password = "******" }; connection.Insert(user1); connection.Insert(user2); connection.Insert(user3); Console.WriteLine(user1); Console.WriteLine(user2); Console.WriteLine(user3); user1 = connection.Get<User>(user2.id); Console.WriteLine("Get user 2: " + user1); try { // will cause a exception since user with id valued 3 doesn't exist user1 = connection.Get<User>(0); } catch (Exception ex) { System.Console.WriteLine("Get user 0: Exception - " + ex.Message); } // will return null instead of throw a exception user1 = connection.Find<User>(0); Console.WriteLine("Find user 0: null? " + (user1 == null)); connection.DropTable<User>(); connection.Close(); }
public void QueryUsers() { IConnection connection = Program.GetOpenConnection(); if (!connection.ExistTable<User>()) connection.CreateTable<User>(); User user1 = new User { username = "******", password = "******" }; User user2 = new User { username = "******", password = "******" }; User user3 = new User { username = "******", password = "******" }; connection.Insert(user1); connection.Insert(user2); connection.Insert(user3); foreach (var user in connection.Query<User>("select * from sample_users")) { Console.WriteLine(user); } connection.DropTable<User>(); connection.Close(); }
public void Transaction() { IConnection connection = Program.GetOpenConnection(); if (!connection.ExistTable<User>()) connection.CreateTable<User>(); User user1 = new User { username = "******", password = "******" }; Int64 id = connection.Insert(user1); Console.WriteLine("Before transaction: " + user1); connection.BeginTransaction(); user1.password = "******"; connection.Update(user1); User user2 = connection.Get<User>(id); Console.WriteLine("In transaction: " + user2); connection.RollbackTransaction(); user2 = connection.Get<User>(id); Console.WriteLine("Rollback transaction: " + user2); connection.DropTable<User>(); connection.Close(); }
public void CRUD() { IConnection connection = Program.GetOpenConnection(); if (!connection.ExistTable<User>()) connection.CreateTable<User>(); User user1 = new User { username = "******", password = "******" }; Int64 id = connection.Insert(user1); Console.WriteLine(user1); user1.password = "******"; connection.Update(user1); Console.WriteLine(user1); User user2 = connection.Get<User>(id); Console.WriteLine(user2); connection.Delete(user2); user2 = connection.Find<User>(id); Console.WriteLine(user2); connection.DropTable<User>(); connection.Close(); }