aboutsummaryrefslogtreecommitdiff
path: root/src/PhotoStore.cs
diff options
context:
space:
mode:
authorGravatar Daniel Smith <rdnlsmith@gmail.com> 2018-08-26 21:22:32 -0400
committerGravatar Daniel Smith <rdnlsmith@gmail.com> 2018-08-26 21:22:32 -0400
commit2ecbe281b0351e630c7730b44c1f4a9c3b3062a5 (patch)
tree4c9ab179dd654230b4f9b29da8437bee9b0fffac /src/PhotoStore.cs
Initial commit
Diffstat (limited to 'src/PhotoStore.cs')
-rw-r--r--src/PhotoStore.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/PhotoStore.cs b/src/PhotoStore.cs
new file mode 100644
index 0000000..e0b292b
--- /dev/null
+++ b/src/PhotoStore.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.Data.Sqlite;
+
+namespace iPhotoExtractor
+{
+ class PhotoStore
+ {
+ private readonly string _sqliteConnectionString;
+
+ public PhotoStore(string pathToDbFile)
+ {
+ _sqliteConnectionString = $"Data Source={pathToDbFile};";
+ }
+
+ public List<Photo> GetAllPhotos()
+ {
+ var photos = new Dictionary<int, Photo>();
+
+ var query =
+@"select
+ spi.primaryKey,
+ spi.caption,
+ se.name,
+ sfi.relativePath
+from SqPhotoInfo spi
+left outer join SqEvent se on se.primaryKey = spi.event
+left outer join SqFileImage sfim on sfim.photoKey = spi.primaryKey
+left outer join SqFileInfo sfi on sfi.primaryKey = sfim.sqFileInfo
+where lower(sfi.relativePath) like 'modified%' or lower(sfi.relativePath) like 'originals%'
+";
+
+ using (var connection = new SqliteConnection(_sqliteConnectionString))
+ {
+ connection.Open();
+
+ using (var command = new SqliteCommand(query, connection))
+ using (SqliteDataReader reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ var id = Convert.ToInt32(reader["primaryKey"]);
+ var photoPath = new PhotoPath(reader["relativePath"].ToString());
+
+ if (!photos.ContainsKey(id))
+ {
+ var caption = reader["caption"].ToString();
+ var albumName = reader["name"].ToString();
+ var photo = new Photo(id, caption, albumName);
+
+ photos.Add(id, photo);
+ }
+
+ photos[id].AddPath(photoPath);
+ }
+ }
+ }
+
+ return photos.Values.ToList();
+ }
+ }
+} \ No newline at end of file