mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-03 19:17:16 -05:00 
			
		
		
		
	Finishing basic sql management.
This commit is contained in:
		
							parent
							
								
									b74fb83a49
								
							
						
					
					
						commit
						f5811b9ce4
					
				@ -17,10 +17,10 @@ namespace Kyoo.Controllers
 | 
			
		||||
            this.libraryManager = libraryManager;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [HttpGet("api/browse")]
 | 
			
		||||
        [HttpGet("api/getall")]
 | 
			
		||||
        public IEnumerable<Show> GetAll()
 | 
			
		||||
        {
 | 
			
		||||
            return libraryManager.QueryShows(null);//new Show[] { new Show(0, "clannad", "Clannad", null, "Best Anime", Status.Finished, 2007, 2008, "", "", "t", "", "", "TvDB=159|Mal=123") };
 | 
			
		||||
            return libraryManager.QueryShows(null);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,7 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Data.SQLite;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.IO;
 | 
			
		||||
 | 
			
		||||
namespace Kyoo.InternalAPI
 | 
			
		||||
{
 | 
			
		||||
@ -16,129 +16,137 @@ namespace Kyoo.InternalAPI
 | 
			
		||||
            Debug.WriteLine("&Library Manager init");
 | 
			
		||||
 | 
			
		||||
            string databasePath = @"C://Projects/database.db";
 | 
			
		||||
            SQLiteConnection.CreateFile(databasePath);
 | 
			
		||||
            sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
 | 
			
		||||
            sqlConnection.Open();
 | 
			
		||||
            
 | 
			
		||||
            string createStatement = @"CREATE TABLE shows(
 | 
			
		||||
					id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					uri TEXT UNIQUE, 
 | 
			
		||||
					title TEXT, 
 | 
			
		||||
					aliases TEXT, 
 | 
			
		||||
					overview TEXT, 
 | 
			
		||||
					status TEXT, 
 | 
			
		||||
					startYear INTEGER, 
 | 
			
		||||
					endYear INTEGER, 
 | 
			
		||||
					imgPrimary TEXT, 
 | 
			
		||||
					imgThumb TEXT, 
 | 
			
		||||
					imgBanner TEXT, 
 | 
			
		||||
					imgLogo TEXT, 
 | 
			
		||||
					imgBackdrop TEXT, 
 | 
			
		||||
					externalIDs TEXT
 | 
			
		||||
				);
 | 
			
		||||
				CREATE TABLE seasons(
 | 
			
		||||
					id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					showID INTEGER, 
 | 
			
		||||
					seasonNumber INTEGER, 
 | 
			
		||||
					title TEXT, 
 | 
			
		||||
					overview TEXT, 
 | 
			
		||||
					imgPrimary TEXT, 
 | 
			
		||||
					year INTEGER, 
 | 
			
		||||
					externalIDs TEXT, 
 | 
			
		||||
					FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				);
 | 
			
		||||
				CREATE TABLE episodes(
 | 
			
		||||
					id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					showID INTEGER, 
 | 
			
		||||
					seasonID INTEGER, 
 | 
			
		||||
					episodeNumber INTEGER, 
 | 
			
		||||
					title TEXT, 
 | 
			
		||||
					overview TEXT, 
 | 
			
		||||
					imgPrimary TEXT, 
 | 
			
		||||
					releaseDate TEXT,  
 | 
			
		||||
					runtime INTEGER, 
 | 
			
		||||
					externalIDs TEXT, 
 | 
			
		||||
					FOREIGN KEY(showID) REFERENCES shows(id), 
 | 
			
		||||
					FOREIGN KEY(seasonID) REFERENCES seasons(id)
 | 
			
		||||
				);
 | 
			
		||||
				CREATE TABLE streams(
 | 
			
		||||
					id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					episodeID INTEGER, 
 | 
			
		||||
					streamIndex INTEGER, 
 | 
			
		||||
					streamType TEXT,
 | 
			
		||||
					codec TEXT, 
 | 
			
		||||
					language TEXT, 
 | 
			
		||||
					channelLayout TEXT, 
 | 
			
		||||
					profile TEXT, 
 | 
			
		||||
					aspectRatio TEXT, 
 | 
			
		||||
					bitRate INTEGER, 
 | 
			
		||||
					sampleRate INTEGER, 
 | 
			
		||||
					isDefault BOOLEAN, 
 | 
			
		||||
					isForced BOOLEAN, 
 | 
			
		||||
					isExternal BOOLEAN, 
 | 
			
		||||
					height INTEGER, 
 | 
			
		||||
					width INTEGER, 
 | 
			
		||||
					frameRate NUMBER, 
 | 
			
		||||
					level NUMBER, 
 | 
			
		||||
					pixelFormat TEXT, 
 | 
			
		||||
					bitDepth INTEGER, 
 | 
			
		||||
					FOREIGN KEY(episodeID) REFERENCES episodes(id)
 | 
			
		||||
				);
 | 
			
		||||
            if (!File.Exists(databasePath))
 | 
			
		||||
            {
 | 
			
		||||
                SQLiteConnection.CreateFile(databasePath);
 | 
			
		||||
                sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
 | 
			
		||||
                sqlConnection.Open();
 | 
			
		||||
 | 
			
		||||
				CREATE TABLE libraries(
 | 
			
		||||
					id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					uri TEXT UNIQUE, 
 | 
			
		||||
					name TEXT
 | 
			
		||||
				);
 | 
			
		||||
				CREATE TABLE librariesLinks(
 | 
			
		||||
					librarieID INTEGER, 
 | 
			
		||||
					showID INTEGER, 
 | 
			
		||||
					FOREIGN KEY(librarieID) REFERENCES libraries(id), 
 | 
			
		||||
					FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				);
 | 
			
		||||
                string createStatement = @"CREATE TABLE shows(
 | 
			
		||||
					    id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					    uri TEXT UNIQUE, 
 | 
			
		||||
					    title TEXT, 
 | 
			
		||||
					    aliases TEXT, 
 | 
			
		||||
					    overview TEXT, 
 | 
			
		||||
					    status TEXT, 
 | 
			
		||||
					    startYear INTEGER, 
 | 
			
		||||
					    endYear INTEGER, 
 | 
			
		||||
					    imgPrimary TEXT, 
 | 
			
		||||
					    imgThumb TEXT, 
 | 
			
		||||
					    imgBanner TEXT, 
 | 
			
		||||
					    imgLogo TEXT, 
 | 
			
		||||
					    imgBackdrop TEXT, 
 | 
			
		||||
					    externalIDs TEXT
 | 
			
		||||
				    );
 | 
			
		||||
				    CREATE TABLE seasons(
 | 
			
		||||
					    id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					    showID INTEGER, 
 | 
			
		||||
					    seasonNumber INTEGER, 
 | 
			
		||||
					    title TEXT, 
 | 
			
		||||
					    overview TEXT, 
 | 
			
		||||
					    imgPrimary TEXT, 
 | 
			
		||||
					    year INTEGER, 
 | 
			
		||||
					    externalIDs TEXT, 
 | 
			
		||||
					    FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				    );
 | 
			
		||||
				    CREATE TABLE episodes(
 | 
			
		||||
					    id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					    showID INTEGER, 
 | 
			
		||||
					    seasonID INTEGER, 
 | 
			
		||||
					    episodeNumber INTEGER, 
 | 
			
		||||
					    title TEXT, 
 | 
			
		||||
					    overview TEXT, 
 | 
			
		||||
					    imgPrimary TEXT, 
 | 
			
		||||
					    releaseDate TEXT,  
 | 
			
		||||
					    runtime INTEGER, 
 | 
			
		||||
					    externalIDs TEXT, 
 | 
			
		||||
					    FOREIGN KEY(showID) REFERENCES shows(id), 
 | 
			
		||||
					    FOREIGN KEY(seasonID) REFERENCES seasons(id)
 | 
			
		||||
				    );
 | 
			
		||||
				    CREATE TABLE streams(
 | 
			
		||||
					    id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					    episodeID INTEGER, 
 | 
			
		||||
					    streamIndex INTEGER, 
 | 
			
		||||
					    streamType TEXT,
 | 
			
		||||
					    codec TEXT, 
 | 
			
		||||
					    language TEXT, 
 | 
			
		||||
					    channelLayout TEXT, 
 | 
			
		||||
					    profile TEXT, 
 | 
			
		||||
					    aspectRatio TEXT, 
 | 
			
		||||
					    bitRate INTEGER, 
 | 
			
		||||
					    sampleRate INTEGER, 
 | 
			
		||||
					    isDefault BOOLEAN, 
 | 
			
		||||
					    isForced BOOLEAN, 
 | 
			
		||||
					    isExternal BOOLEAN, 
 | 
			
		||||
					    height INTEGER, 
 | 
			
		||||
					    width INTEGER, 
 | 
			
		||||
					    frameRate NUMBER, 
 | 
			
		||||
					    level NUMBER, 
 | 
			
		||||
					    pixelFormat TEXT, 
 | 
			
		||||
					    bitDepth INTEGER, 
 | 
			
		||||
					    FOREIGN KEY(episodeID) REFERENCES episodes(id)
 | 
			
		||||
				    );
 | 
			
		||||
 | 
			
		||||
				CREATE TABLE studios(
 | 
			
		||||
					id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					uri TEXT UNIQUE, 
 | 
			
		||||
					name TEXT
 | 
			
		||||
					);
 | 
			
		||||
					CREATE TABLE studiosLinks(
 | 
			
		||||
					studioID INTEGER, 
 | 
			
		||||
					showID INTEGER, 
 | 
			
		||||
					FOREIGN KEY(studioID) REFERENCES studios(id), 
 | 
			
		||||
					FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				);
 | 
			
		||||
				    CREATE TABLE libraries(
 | 
			
		||||
					    id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					    uri TEXT UNIQUE, 
 | 
			
		||||
					    name TEXT
 | 
			
		||||
				    );
 | 
			
		||||
				    CREATE TABLE librariesLinks(
 | 
			
		||||
					    librarieID INTEGER, 
 | 
			
		||||
					    showID INTEGER, 
 | 
			
		||||
					    FOREIGN KEY(librarieID) REFERENCES libraries(id), 
 | 
			
		||||
					    FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				    );
 | 
			
		||||
 | 
			
		||||
				CREATE TABLE people(
 | 
			
		||||
					id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					uri TEXT UNIQUE, 
 | 
			
		||||
					name TEXT, 
 | 
			
		||||
					imgPrimary TEXT, 
 | 
			
		||||
					externalIDs TEXT
 | 
			
		||||
				);
 | 
			
		||||
				CREATE TABLE peopleLinks(
 | 
			
		||||
					peopleID INTEGER, 
 | 
			
		||||
					showID INTEGER, 
 | 
			
		||||
					role TEXT, 
 | 
			
		||||
					type TEXT, 
 | 
			
		||||
					FOREIGN KEY(peopleID) REFERENCES people(id), 
 | 
			
		||||
					FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				);
 | 
			
		||||
				    CREATE TABLE studios(
 | 
			
		||||
					    id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					    uri TEXT UNIQUE, 
 | 
			
		||||
					    name TEXT
 | 
			
		||||
					    );
 | 
			
		||||
				    CREATE TABLE studiosLinks(
 | 
			
		||||
					    studioID INTEGER, 
 | 
			
		||||
					    showID INTEGER, 
 | 
			
		||||
					    FOREIGN KEY(studioID) REFERENCES studios(id), 
 | 
			
		||||
					    FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				    );
 | 
			
		||||
 | 
			
		||||
				CREATE TABLE genres(
 | 
			
		||||
					id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					uri TEXT UNIQUE, 
 | 
			
		||||
					name TEXT
 | 
			
		||||
				);
 | 
			
		||||
				CREATE TABLE genresLinks(
 | 
			
		||||
					genreID INTEGER, 
 | 
			
		||||
					showID INTEGER, 
 | 
			
		||||
					FOREIGN KEY(genreID) REFERENCES genres(id), 
 | 
			
		||||
					FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				);";
 | 
			
		||||
				    CREATE TABLE people(
 | 
			
		||||
					    id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					    uri TEXT UNIQUE, 
 | 
			
		||||
					    name TEXT, 
 | 
			
		||||
					    imgPrimary TEXT, 
 | 
			
		||||
					    externalIDs TEXT
 | 
			
		||||
				    );
 | 
			
		||||
				    CREATE TABLE peopleLinks(
 | 
			
		||||
					    peopleID INTEGER, 
 | 
			
		||||
					    showID INTEGER, 
 | 
			
		||||
					    role TEXT, 
 | 
			
		||||
					    type TEXT, 
 | 
			
		||||
					    FOREIGN KEY(peopleID) REFERENCES people(id), 
 | 
			
		||||
					    FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				    );
 | 
			
		||||
 | 
			
		||||
            SQLiteCommand createCmd = new SQLiteCommand(createStatement, sqlConnection);
 | 
			
		||||
            createCmd.ExecuteNonQuery();
 | 
			
		||||
				    CREATE TABLE genres(
 | 
			
		||||
					    id INTEGER PRIMARY KEY UNIQUE, 
 | 
			
		||||
					    uri TEXT UNIQUE, 
 | 
			
		||||
					    name TEXT
 | 
			
		||||
				    );
 | 
			
		||||
				    CREATE TABLE genresLinks(
 | 
			
		||||
					    genreID INTEGER, 
 | 
			
		||||
					    showID INTEGER, 
 | 
			
		||||
					    FOREIGN KEY(genreID) REFERENCES genres(id), 
 | 
			
		||||
					    FOREIGN KEY(showID) REFERENCES shows(id)
 | 
			
		||||
				    );";
 | 
			
		||||
 | 
			
		||||
                SQLiteCommand createCmd = new SQLiteCommand(createStatement, sqlConnection);
 | 
			
		||||
                createCmd.ExecuteNonQuery();
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
 | 
			
		||||
                sqlConnection.Open();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Debug.WriteLine("&Sql Database initated.");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -1,19 +1,20 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
 | 
			
		||||
namespace Kyoo.Models
 | 
			
		||||
{
 | 
			
		||||
    public class Show
 | 
			
		||||
    {
 | 
			
		||||
        public readonly int id;
 | 
			
		||||
        public readonly long id;
 | 
			
		||||
 | 
			
		||||
        public string Uri;
 | 
			
		||||
        public string Title;
 | 
			
		||||
        public List<string> Aliases;
 | 
			
		||||
        public string Overview;
 | 
			
		||||
        public Status Status;
 | 
			
		||||
        public Status? Status;
 | 
			
		||||
 | 
			
		||||
        public int StartYear;
 | 
			
		||||
        public int EndYear;
 | 
			
		||||
        public long? StartYear;
 | 
			
		||||
        public long? EndYear;
 | 
			
		||||
 | 
			
		||||
        public string ImgPrimary;
 | 
			
		||||
        public string ImgThumb;
 | 
			
		||||
@ -24,7 +25,7 @@ namespace Kyoo.Models
 | 
			
		||||
        public string ExternalIDs;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public Show(int id, string uri, string title, List<string> aliases, string overview, Status status, int startYear, int endYear, string imgPrimary, string imgThumb, string imgBanner, string imgLogo, string imgBackdrop, string externalIDs)
 | 
			
		||||
        public Show(long id, string uri, string title, List<string> aliases, string overview, Status? status, long? startYear, long? endYear, string imgPrimary, string imgThumb, string imgBanner, string imgLogo, string imgBackdrop, string externalIDs)
 | 
			
		||||
        {
 | 
			
		||||
            this.id = id;
 | 
			
		||||
            Uri = uri;
 | 
			
		||||
@ -42,23 +43,22 @@ namespace Kyoo.Models
 | 
			
		||||
            ExternalIDs = externalIDs;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Cast error here (Unable to cast object of type 'System.Int64' to type 'System.Int32'.)
 | 
			
		||||
        public static Show FromReader(System.Data.SQLite.SQLiteDataReader reader)
 | 
			
		||||
        {
 | 
			
		||||
            return new Show((int)reader["id"], 
 | 
			
		||||
                (string)reader["uri"], 
 | 
			
		||||
                (string)reader["title"], 
 | 
			
		||||
                null,
 | 
			
		||||
                (string)reader["overview"],
 | 
			
		||||
                Status.Finished, 
 | 
			
		||||
                (int)reader["startYear"], 
 | 
			
		||||
                (int)reader["endYear"],
 | 
			
		||||
                (string)reader["imgPrimary"],
 | 
			
		||||
                (string)reader["imgThumb"],
 | 
			
		||||
                (string)reader["imgBanner"],
 | 
			
		||||
                (string)reader["imgLogo"],
 | 
			
		||||
                (string)reader["imgBackdrop"],
 | 
			
		||||
                (string)reader["externalIDs"]);
 | 
			
		||||
            return new Show((long)reader["id"],
 | 
			
		||||
                reader["uri"] as string,
 | 
			
		||||
                reader["title"] as string,
 | 
			
		||||
                (reader["aliases"] as string)?.Split('|').ToList() ?? null,
 | 
			
		||||
                reader["overview"] as string,
 | 
			
		||||
                reader["status"] as Status?,
 | 
			
		||||
                reader["startYear"] as long?, 
 | 
			
		||||
                reader["endYear"] as long?,
 | 
			
		||||
                reader["imgPrimary"] as string, 
 | 
			
		||||
                reader["imgThumb"] as string,
 | 
			
		||||
                reader["imgBanner"] as string,
 | 
			
		||||
                reader["imgLogo"] as string,
 | 
			
		||||
                reader["imgBackdrop"] as string,
 | 
			
		||||
                reader["externalIDs"] as string);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user