From 8ec4dd53e8e9afc28e8b0b18963dd131d8cbf982 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 20 Mar 2015 21:05:17 -0700 Subject: [PATCH] Add code contracts, update raw version number, bump version numbers. --- SQLitePCL.pretty.Async.nuspec | 4 +- SQLitePCL.pretty.Orm.nuspec | 8 ++-- .../SQLitePCL.pretty.Orm.csproj | 46 ++++++++++++++++++- SQLitePCL.pretty.Orm/TableMappedStatement.cs | 3 ++ SQLitePCL.pretty.Orm/TableMapping.Delete.cs | 28 +++++++++++ SQLitePCL.pretty.Orm/TableMapping.Find.cs | 19 ++++++++ .../TableMapping.InsertOrReplace.cs | 19 ++++++++ SQLitePCL.pretty.Orm/TableMapping.cs | 22 +++++++++ SQLitePCL.pretty.nuspec | 7 +-- .../SQLitePCL.pretty.tests.x86.csproj | 3 +- SQLitePCL.pretty.tests/packages.config | 2 +- SQLitePCL.pretty/SQLitePCL.pretty.csproj | 4 +- SQLitePCL.pretty/packages.config | 2 +- 13 files changed, 152 insertions(+), 15 deletions(-) diff --git a/SQLitePCL.pretty.Async.nuspec b/SQLitePCL.pretty.Async.nuspec index 2796db3..77de7c9 100644 --- a/SQLitePCL.pretty.Async.nuspec +++ b/SQLitePCL.pretty.Async.nuspec @@ -2,7 +2,7 @@ SQLitePCL.pretty.Async - 0.0.12-pre2 + 0.0.12-pre3 SQLitePCL.pretty.Async David Bordoley https://github.com/bordoley/SQLitePCL.pretty/blob/master/LICENSE @@ -15,7 +15,7 @@ - + diff --git a/SQLitePCL.pretty.Orm.nuspec b/SQLitePCL.pretty.Orm.nuspec index deaf086..d1eece0 100644 --- a/SQLitePCL.pretty.Orm.nuspec +++ b/SQLitePCL.pretty.Orm.nuspec @@ -2,21 +2,21 @@ SQLitePCL.pretty.Orm - 0.0.12-pre2 + 0.0.12-pre3 SQLitePCL.pretty.Orm David Bordoley https://github.com/bordoley/SQLitePCL.pretty/blob/master/LICENSE https://github.com/bordoley/SQLitePCL.pretty false Table mapping ORM for SQLitePCL.pretty - Provides a simple table mapping ORM similar to the one provided by SQLite-Net. + Provides a simple table mapping ORM for SQLitePCL.pretty. portable sqlite pcl rx reactive LINQ orm - - + + diff --git a/SQLitePCL.pretty.Orm/SQLitePCL.pretty.Orm.csproj b/SQLitePCL.pretty.Orm/SQLitePCL.pretty.Orm.csproj index 014f1e4..d384cc3 100644 --- a/SQLitePCL.pretty.Orm/SQLitePCL.pretty.Orm.csproj +++ b/SQLitePCL.pretty.Orm/SQLitePCL.pretty.Orm.csproj @@ -1,4 +1,4 @@ - + Debug @@ -10,6 +10,7 @@ SQLitePCL.pretty.Orm Profile259 v4.5 + 1 true @@ -29,6 +30,49 @@ 4 false bin\Release\SQLitePCL.pretty.Orm.xml + True + False + True + False + False + False + True + True + True + True + True + True + True + True + False + True + False + True + False + False + False + False + True + False + True + True + True + False + True + + + + + + + + True + False + False + True + Full + Build + 0 diff --git a/SQLitePCL.pretty.Orm/TableMappedStatement.cs b/SQLitePCL.pretty.Orm/TableMappedStatement.cs index 2b26442..26085d5 100644 --- a/SQLitePCL.pretty.Orm/TableMappedStatement.cs +++ b/SQLitePCL.pretty.Orm/TableMappedStatement.cs @@ -20,6 +20,9 @@ public static class TableMappedStatement /// The mapped type. public static void Bind(this ITableMappedStatement This, T obj) { + Contract.Requires(This != null); + Contract.Requires(obj != null); + This.Bind(This.Mapping, obj); } diff --git a/SQLitePCL.pretty.Orm/TableMapping.Delete.cs b/SQLitePCL.pretty.Orm/TableMapping.Delete.cs index de7c7e4..b4c8771 100644 --- a/SQLitePCL.pretty.Orm/TableMapping.Delete.cs +++ b/SQLitePCL.pretty.Orm/TableMapping.Delete.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -17,6 +18,9 @@ public static partial class TableMapping /// The mapped type public static IStatement PrepareDeleteStatement(this IDatabaseConnection This, ITableMapping tableMapping) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + return This.PrepareDelete(tableMapping.TableName, tableMapping.PrimaryKeyColumn()); } @@ -48,6 +52,9 @@ private static IEnumerable> YieldDeleteAll(this IDatabas /// The mapped type. public static bool TryDelete(this IDatabaseConnection This, ITableMapping tableMapping, long primaryKey, out T deleted) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + var result = This.YieldDeleteAll(tableMapping, new long[] { primaryKey }).FirstOrDefault(); if (result.Value != null) { @@ -71,6 +78,10 @@ public static bool TryDelete(this IDatabaseConnection This, ITableMapping /// The mapped type. public static IReadOnlyDictionary DeleteAll(this IDatabaseConnection This, ITableMapping tableMapping, IEnumerable primaryKeys) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(primaryKeys != null); + return This.RunInTransaction(_ => This.YieldDeleteAll(tableMapping, primaryKeys) .Where(kvp => kvp.Value != null) @@ -88,6 +99,10 @@ public static IReadOnlyDictionary DeleteAll(this IDatabaseConnection /// The mapped type. public static Task> DeleteAllAsync(this IAsyncDatabaseConnection This, ITableMapping tableMapping, IEnumerable primaryKeys, CancellationToken ct) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(primaryKeys != null); + return This.Use((db,_) => db.DeleteAll(tableMapping, primaryKeys), ct); } @@ -101,6 +116,10 @@ public static Task> DeleteAllAsync(this IAsyncDat /// The mapped type. public static Task> DeleteAllAsync(this IAsyncDatabaseConnection This, ITableMapping tableMapping, IEnumerable primaryKeys) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(primaryKeys != null); + return This.DeleteAllAsync(tableMapping, primaryKeys, CancellationToken.None); } @@ -112,6 +131,9 @@ public static Task> DeleteAllAsync(this IAsyncDat /// The mapped type. public static void DeleteAllRows(this IDatabaseConnection This, ITableMapping tableMapping) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + This.DeleteAll(tableMapping.TableName); } @@ -125,6 +147,9 @@ public static void DeleteAllRows(this IDatabaseConnection This, ITableMapping /// The mapped type. public static Task DeleteAllRowsAsync(this IAsyncDatabaseConnection This, ITableMapping tableMapping, CancellationToken ct) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + return This.Use((db, _) => db.DeleteAllRows(tableMapping), ct); } @@ -137,6 +162,9 @@ public static Task DeleteAllRowsAsync(this IAsyncDatabaseConnection This, ITa /// The mapped type. public static Task DeleteAllRowsAsync(this IAsyncDatabaseConnection This, ITableMapping tableMapping) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + return This.DeleteAllRowsAsync(tableMapping, CancellationToken.None); } } diff --git a/SQLitePCL.pretty.Orm/TableMapping.Find.cs b/SQLitePCL.pretty.Orm/TableMapping.Find.cs index 5960390..c9efdad 100644 --- a/SQLitePCL.pretty.Orm/TableMapping.Find.cs +++ b/SQLitePCL.pretty.Orm/TableMapping.Find.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Linq; using System.Runtime.CompilerServices; using System.Threading; @@ -30,6 +31,9 @@ private static string Find(this ITableMapping This) /// The mapped type public static ITableMappedStatement PrepareFindStatement(this IDatabaseConnection This, ITableMapping tableMapping) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + return new TableMappedStatement(This.PrepareStatement(tableMapping.Find()), tableMapping); } @@ -56,6 +60,9 @@ private static IEnumerable> YieldFindAll(this IDatabaseC /// The mapped type. public static bool TryFind(this IDatabaseConnection This, ITableMapping tableMapping, long primaryKey, out T value) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + var result = This.YieldFindAll(tableMapping, new long[] { primaryKey }).FirstOrDefault(); if (result.Value != null) @@ -78,6 +85,10 @@ public static bool TryFind(this IDatabaseConnection This, ITableMapping ta /// The mapped type. public static IReadOnlyDictionary FindAll(this IDatabaseConnection This, ITableMapping tableMapping, IEnumerable primaryKeys) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(primaryKeys != null); + return This.YieldFindAll(tableMapping, primaryKeys) .Where(kvp => kvp.Value != null) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); @@ -98,6 +109,10 @@ public static Task> FindAllAsync( IEnumerable primaryKeys, CancellationToken ct) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(primaryKeys != null); + return This.Use((db,_) => db.FindAll(tableMapping, primaryKeys), ct); } @@ -114,6 +129,10 @@ public static Task> FindAllAsync( ITableMapping tableMapping, IEnumerable primaryKeys) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(primaryKeys != null); + return This.FindAllAsync(tableMapping, primaryKeys, CancellationToken.None); } } diff --git a/SQLitePCL.pretty.Orm/TableMapping.InsertOrReplace.cs b/SQLitePCL.pretty.Orm/TableMapping.InsertOrReplace.cs index b5722d3..cb62bbb 100644 --- a/SQLitePCL.pretty.Orm/TableMapping.InsertOrReplace.cs +++ b/SQLitePCL.pretty.Orm/TableMapping.InsertOrReplace.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -22,6 +23,8 @@ private static string InsertOrReplace(this ITableMapping tableMapping) /// The mapped type public static ITableMappedStatement PrepareInsertOrReplaceStatement(this IDatabaseConnection This, ITableMapping tableMapping) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); return new TableMappedStatement(This.PrepareStatement(tableMapping.InsertOrReplace()), tableMapping); } @@ -49,6 +52,10 @@ private static IEnumerable> YieldInsertOrReplaceAll(this ID /// The mapped type. public static T InsertOrReplace(this IDatabaseConnection This, ITableMapping tableMapping, T obj) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(obj != null); + return This.YieldInsertOrReplaceAll(tableMapping, new T[] {obj}).First().Value; } @@ -62,6 +69,10 @@ public static T InsertOrReplace(this IDatabaseConnection This, ITableMapping< /// The mapped type. public static IReadOnlyDictionary InsertOrReplaceAll(this IDatabaseConnection This, ITableMapping tableMapping, IEnumerable objects) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(objects != null); + return This.RunInTransaction(_ => This.YieldInsertOrReplaceAll(tableMapping, objects).ToDictionary(kvp => kvp.Key, kvp => kvp.Value)); } @@ -81,6 +92,10 @@ public static Task> InsertOrReplaceAllAsync( IEnumerable objects, CancellationToken ct) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(objects != null); + return This.Use((db, _) => db.InsertOrReplaceAll(tableMapping, objects), ct); } @@ -97,6 +112,10 @@ public static Task> InsertOrReplaceAllAsync( ITableMapping tableMapping, IEnumerable objects) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + Contract.Requires(objects != null); + return This.InsertOrReplaceAllAsync(tableMapping, objects, CancellationToken.None); } } diff --git a/SQLitePCL.pretty.Orm/TableMapping.cs b/SQLitePCL.pretty.Orm/TableMapping.cs index 8711946..89b5a33 100644 --- a/SQLitePCL.pretty.Orm/TableMapping.cs +++ b/SQLitePCL.pretty.Orm/TableMapping.cs @@ -24,6 +24,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.IO; using System.Linq; @@ -64,6 +65,9 @@ internal static TableQuery Query(this ITableMapping This) /// The mapped type. public static void InitTable(this IDatabaseConnection This, ITableMapping tableMapping) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + This.RunInTransaction(_ => { This.CreateTableIfNotExists(tableMapping.TableName, CreateFlags.None, tableMapping.Columns); @@ -90,6 +94,9 @@ public static void InitTable(this IDatabaseConnection This, ITableMapping /// The mapped type. public static Task InitTableAsync(this IAsyncDatabaseConnection This, ITableMapping tableMapping, CancellationToken cancellationToken) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + return This.Use((db, ct) => db.InitTable(tableMapping), cancellationToken); } @@ -102,6 +109,9 @@ public static Task InitTableAsync(this IAsyncDatabaseConnection This, ITableM /// The mapped type. public static Task InitTableAsync(this IAsyncDatabaseConnection This, ITableMapping tableMapping) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + return This.InitTableAsync(tableMapping, CancellationToken.None); } @@ -145,6 +155,9 @@ private static string PrimaryKeyColumn(this ITableMapping This) /// The mapped type. public static void DropTableIfExists(this IDatabaseConnection This, ITableMapping tableMapping) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + This.DropTableIfExists(tableMapping.TableName); } @@ -158,6 +171,9 @@ public static void DropTableIfExists(this IDatabaseConnection This, ITableMap /// The mapped type. public static Task DropTableIfExistsAsync(this IAsyncDatabaseConnection This, ITableMapping tableMapping, CancellationToken ct) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + return This.Use((db, _) => db.DropTableIfExists(tableMapping), ct); } @@ -170,6 +186,9 @@ public static Task DropTableIfExistsAsync(this IAsyncDatabaseConnection This, /// The mapped type. public static Task DropTableIfExistsAsync(this IAsyncDatabaseConnection This, ITableMapping tableMapping) { + Contract.Requires(This != null); + Contract.Requires(tableMapping != null); + return This.DropTableIfExistsAsync(tableMapping, CancellationToken.None); } @@ -194,6 +213,9 @@ public static ITableMapping Create() /// The mapped type. public static ITableMapping Create(Func builder, Func build) { + Contract.Requires(builder != null); + Contract.Requires(build != null); + var mappedType = typeof(T); var tableName = mappedType.GetTableName(); var props = mappedType.GetPublicInstanceProperties(); diff --git a/SQLitePCL.pretty.nuspec b/SQLitePCL.pretty.nuspec index 41af1df..16ee0eb 100644 --- a/SQLitePCL.pretty.nuspec +++ b/SQLitePCL.pretty.nuspec @@ -2,7 +2,7 @@ SQLitePCL.pretty - 0.0.12-pre2 + 0.0.12-pre3 SQLitePCL.pretty David Bordoley https://github.com/bordoley/SQLitePCL.pretty/blob/master/LICENSE @@ -11,14 +11,15 @@ A pretty face on top of SQLitePCL.raw SQLitePCL.pretty wraps the C like SQLiteAPI provided by SQLitePCL.raw with a friendly C# object oriented API. Notable features include support for using LINQ expressions on SQL query results, SQLite events exposed as C# events, and the ability to take advantage of advance SQLite features, such as collation, aggregate, scalar, and commit hook functions. -For asynchronous query support, an additional companion API is available. See: SQLitePCL.pretty.Async +For asynchronous query support, an additional companion API is available. See: https://www.nuget.org/packages/SQLitePCL.pretty.Async/ +A simple table mapped ORM is also available. See https://www.nuget.org/packages/SQLitePCL.pretty.Orm/ portable sqlite pcl LINQ - + diff --git a/SQLitePCL.pretty.tests/SQLitePCL.pretty.tests.x86.csproj b/SQLitePCL.pretty.tests/SQLitePCL.pretty.tests.x86.csproj index 0b17344..9b9949e 100644 --- a/SQLitePCL.pretty.tests/SQLitePCL.pretty.tests.x86.csproj +++ b/SQLitePCL.pretty.tests/SQLitePCL.pretty.tests.x86.csproj @@ -64,7 +64,7 @@ ..\packages\NUnit.3.0.0-alpha-4\lib\net45\nunit.framework.dll - ..\packages\SQLitePCL.raw_basic.0.7.2-pre1\lib\net45\SQLitePCL.raw.dll + ..\packages\SQLitePCL.raw.0.8.0-pre1\lib\net45\SQLitePCL.raw.dll @@ -134,6 +134,7 @@ + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. diff --git a/SQLitePCL.pretty.tests/packages.config b/SQLitePCL.pretty.tests/packages.config index b9ff910..50efe95 100644 --- a/SQLitePCL.pretty.tests/packages.config +++ b/SQLitePCL.pretty.tests/packages.config @@ -6,5 +6,5 @@ - + \ No newline at end of file diff --git a/SQLitePCL.pretty/SQLitePCL.pretty.csproj b/SQLitePCL.pretty/SQLitePCL.pretty.csproj index f59ca26..2828e12 100644 --- a/SQLitePCL.pretty/SQLitePCL.pretty.csproj +++ b/SQLitePCL.pretty/SQLitePCL.pretty.csproj @@ -150,13 +150,13 @@ + - ..\packages\SQLitePCL.raw_basic.0.7.2-pre1\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLitePCL.raw.dll + ..\packages\SQLitePCL.raw.0.8.0-pre1\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLitePCL.raw.dll - \ No newline at end of file diff --git a/SQLitePCL.pretty/packages.config b/SQLitePCL.pretty/packages.config index 6fa73cf..b5ea3f3 100644 --- a/SQLitePCL.pretty/packages.config +++ b/SQLitePCL.pretty/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file