public void ShowSqlOutput() { var sqlBuilder = new SqlClient.SqlClientSqlBuilder<TestTable>(); var pgBuilder = new PgSql.PgSqlBuilder<TestTable>(); Console.WriteLine(sqlBuilder.ObjectName); Console.WriteLine(pgBuilder.ObjectName); Console.WriteLine("Inserts"); Console.WriteLine(sqlBuilder.InsertString()); Console.WriteLine(pgBuilder.InsertString()); var table = new TestTable(); var mutator = table.SetProperties(new { Name = "Hallo", ApeShit = "Fjert" }); Console.WriteLine("Updates"); Console.WriteLine(sqlBuilder.UpdateString()); Console.WriteLine(pgBuilder.UpdateString()); Console.WriteLine(sqlBuilder.UpdateString(mutator)); Console.WriteLine(pgBuilder.UpdateString(mutator)); Console.WriteLine("Deletes"); Console.WriteLine(sqlBuilder.DeleteString()); Console.WriteLine(pgBuilder.DeleteString()); Console.WriteLine("Find By Id"); Console.WriteLine(sqlBuilder.FindByIdString(table)); Console.WriteLine(pgBuilder.FindByIdString(table)); }
public void PgSql() { PgSqlCommandExecutor.Configure(); using (var connection = new Npgsql.NpgsqlConnection("host=localhost;username=postgres;password=Norther;database=Test")) { connection.Open(); using (var transaction = connection.BeginTransaction()) { var testData = new TestTable() { Foo = "Foo", Name = "Hello", TheDate = DateTime.Now }; TestTable result; using (Time(elapsed => Console.WriteLine("Insert : " + elapsed))) { result = connection.Insert(testData, transaction); } Console.WriteLine("Database generated UID : " + result.TheSecondId); List<TestTable> bulkResult; using (Time(elapsed => Console.WriteLine("Bulk insert : " + elapsed))) { bulkResult = connection.Insert(Enumerable.Range(0, 100).Select(i => new TestTable() { Name = i.ToString() }), transaction).ToList(); Assert.AreEqual(100, bulkResult.Count()); } using (Time(elapsed => Console.WriteLine("Bulk update : " + elapsed))) { bulkResult = connection.Update( bulkResult.Select(item => item.SetProperties(new TestTable() { Name = item.Name + " strongly typed mutation" })), transaction).ToList(); } using (Time(elapsed => Console.WriteLine("Update : " + elapsed))) { var newDate = DateTime.Now.AddYears(-50); var update = connection.Update( result.SetProperties( new { TheDate = newDate } ), transaction ); Assert.AreEqual(newDate.Year, update.TheDate.Year); } using (Time(elapsed => Console.WriteLine("FindById : " + elapsed))) { Assert.IsNotNull(connection.FindById<TestTable>(new { result.Id, result.TheSecondId }, transaction)); } transaction.Commit(); } } }