This commit is contained in:
Jamie.Rees 2016-11-07 14:46:44 +00:00
commit 367ca391b1
7 changed files with 160 additions and 0 deletions

View file

@ -0,0 +1,42 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: RequestQueue.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using Dapper.Contrib.Extensions;
namespace PlexRequests.Store.Models
{
[Table("RequestQueue")]
public class RequestQueue : Entity
{
public int PrimaryIdentifier { get; set; }
public RequestType Type { get; set; }
public byte[] Content { get; set; }
}
}

View file

@ -69,6 +69,7 @@
<Compile Include="Models\PlexEpisodes.cs" />
<Compile Include="Models\PlexUsers.cs" />
<Compile Include="Models\Plex\MetadataItems.cs" />
<Compile Include="Models\RequestQueue.cs" />
<Compile Include="Models\ScheduledJobs.cs" />
<Compile Include="Models\RequestLimit.cs" />
<Compile Include="Models\UsersToNotify.cs" />

View file

@ -327,5 +327,22 @@ namespace PlexRequests.Store.Repository
throw;
}
}
public async Task DeleteAllAsync(string tableName)
{
try
{
ResetCache();
using (var db = Config.DbConnection())
{
db.Open();
await db.ExecuteAsync($"delete from {tableName}");
}
}
catch (SqliteException e) when (e.ErrorCode == SQLiteErrorCode.Corrupt)
{
Log.Fatal(CorruptMessage);
throw;
}
}
}
}

View file

@ -85,5 +85,6 @@ namespace PlexRequests.Store.Repository
IEnumerable<T> Custom(Func<IDbConnection, IEnumerable<T>> func);
Task<IEnumerable<T>> CustomAsync(Func<IDbConnection, Task<IEnumerable<T>>> func);
void DeleteAll(string tableName);
Task DeleteAllAsync(string tableName);
}
}

View file

@ -131,4 +131,15 @@ CREATE TABLE IF NOT EXISTS PlexEpisodes
);
CREATE UNIQUE INDEX IF NOT EXISTS PlexEpisodes_Id ON PlexEpisodes (Id);
CREATE INDEX IF NOT EXISTS PlexEpisodes_ProviderId ON PlexEpisodes (ProviderId);
CREATE TABLE IF NOT EXISTS RequestQueue
(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
PrimaryIdentifier INTEGER NOT NULL,
Type INTEGER NOT NULL,
Content BLOB NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS PlexUsers_Id ON PlexUsers (Id);
COMMIT;