Skip to content

Commit

Permalink
Simplified query
Browse files Browse the repository at this point in the history
  • Loading branch information
luizen committed Apr 24, 2022
1 parent e186897 commit e09c2e8
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net6.0/als-tools.dll",
//"args": ["--locate=HG2;bx_tunner", "--folder=/Users/zenluiz/Desktop/Testes ALS"],
//"args": ["--locate=radiator"],
"args": ["--locate=kickbox;replika"],
// "args": ["--list"],
"args": ["--initdb", "--folder=/Users/zenluiz/Desktop/Testes ALS"],
// "args": ["--initdb", "--folder=/Users/zenluiz/Desktop/Testes ALS"],
// "args": ["--initdb", "--folder=/Users/zenluiz/Splice"],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand Down
56 changes: 4 additions & 52 deletions Infrastructure/Repositories/LiveProjectRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,64 +39,16 @@ public IEnumerable<LiveProject> GetAllProjects()

public IEnumerable<LiveProject> GetProjectsContainingPlugins(string[] pluginsToLocate)
{
// var col = liteDb.GetCollection<LiveProject>("LiveProject");

// var pluginsList = pluginsToLocate

// var projects = col
// .Query()
// .Where(proj => proj.Plugins != null && proj.Plugins.Any(k => pluginsToLocate.Any(x => k.Name.Contains(x, StringComparison.InvariantCultureIgnoreCase))))
// .Select(p => p)
// .ToEnumerable();

// var projects = col
// .Query()
// .Where(proj => proj.Plugins.Where(plugin => pluginsToLocate.Contains(plugin.Name)).Any())
// .Select(p => p)
// .ToEnumerable();

// var projects = col
// .Query()
// .Where(proj =>
// proj.Plugins.Where(plugin =>
// pluginsToLocate.Any(p => p.Contains(plugin.Name, StringComparison.InvariantCultureIgnoreCase))
// ).Any()
// )
// .Select(p => p)
// .ToEnumerable();

// var projects = col
// .Include(x => x.Plugins)
// .FindAll()
// .Where(p => p.Plugins.Intersect(pluginsToLocate))

//TODO: implement it correctly, using DB query
//TODO: implement it correctly, using DB query
var projects = GetAllProjects();
IList<LiveProject> res = new List<LiveProject>();
foreach (var p in projects)
foreach (var proj in projects)
{
var plugins = p.Tracks.Select(x => x.Plugins).SelectMany(x => x);
if (plugins.Any(x => pluginsToLocate.Any(y => x.Key.Contains(y, StringComparison.InvariantCultureIgnoreCase))))
res.Add(p);
// if (p.Plugins.Any(x => pluginsToLocate.Any(y => x.Key.Contains(y, StringComparison.InvariantCultureIgnoreCase))))
// res.Add(p);
if (proj.Tracks.Any(track => track.Plugins.Any(plugin => pluginsToLocate.Any(plugToLocate => plugin.Key.Contains(plugToLocate, StringComparison.InvariantCultureIgnoreCase)))))
res.Add(proj);
}

return res.AsEnumerable();

// var pluginToLocate = pluginsToLocate[0];
// var col = liteDb.GetCollection<LiveProject>("LiveProject");

// var query = @"SELECT { $.*, $.Plugins[*] FROM LiveProject } WHERE $.Plugins[*].Title LIKE '%" + pluginToLocate + "%'";
// var s = liteDb.Execute(query).ToList();

// var res = col.Query()
// .Where(proj => proj.Plugins.Any(p => p.Key.Contains(pluginToLocate, StringComparison.InvariantCultureIgnoreCase)).Any())
// .Select(x => x);

// return res.ToEnumerable();

// return null;
}

public bool Insert(LiveProject project)
Expand Down
100 changes: 100 additions & 0 deletions TEMP.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// var col = liteDb.GetCollection<LiveProject>("LiveProject");

// var colall = liteDb.GetCollection<LiveProject>("LiveProject");
// var all = colall.FindAll().Where(pr => pr.Tracks.Any(tr => tr.Plugins.Any(pl => pl.Value.Name.ToLower() == "decapitator"))).ToList();

// // var pluginsList = pluginsToLocate

// // var q1 = col.Find(proj => proj.Tracks != null && proj.Tracks.Any(track => track.Plugins != null && track
// // .Plugins.Any(plugin => pluginsToLocate.Contains(plugin.Key))
// // )).ToList();

// var q1 = col.Query().Where(proj => proj.Name == "Industrial Acid Techno Youtube.als");
// // var col1 = q1.Select(x => x);
// var col1 = q1.First();

// // var proj = col1.First();

// var a = q1.Where(x => x.Tracks.Where(x => x.Plugins != null && x.Plugins.Count > 0).Any()).Select(x => x).ToList();


// // var b = col.Query().Where(x => x.Tracks.Where(x => x.Plugins != null && x.Plugins.Any(p => p.Value.Name == "Decapitator")).Any()).Select(x => x).ToList();
// // {LiteDB.LiteException: Any/All requires simple parameter on left side. Eg: `x => x.Phones.Select(p => p.Number).Any(n => n > 5)`

// // var b = col.Query().Where(x => x.Tracks.Where(x => x.Plugins != null && x.Plugins.Keys.Any(k => k.Equals("Decapitator"))).Any()).Select(x => x).ToList();
// // var b = col.Query().Where(x => x.Tracks.Where(x => x.Plugins.Where(p => p.Value.Name == "Decapitator").Count() > 0).Any()).Select(x => x).ToList();
// var c = col
// .Query()
// .Where(proj => proj.Name == "Industrial Acid Techno Youtube.als")
// .Where(x => x.Tracks.Where(x => x.Plugins.Values.Where(v => v.Name.Length > 5).Count() > 0).Count() > 0)
// .Select(x => x)
// .ToList();

// var q1 = col.Find(proj => proj.Tracks.Count > 40)
// .Select(x => x.Tracks)
// .ToList();

// var q2 = col.FindAll().ToList();

// var q3 = col.Query().Select(x => x).ToList();



// var p1 = col
// .Query()
// .Where(proj => proj.Tracks.Any(track => track.Name.Length > 10))
// .Select(proj => proj)
// .ToList();

// var projects = col
// .Query()
// .Where(proj => proj
// .Tracks.Any(track => track
// .Plugins.Any(plugin => pluginsToLocate.Contains(plugin.Key))
// )
// )
// .Select(proj => proj)
// .ToEnumerable();

//return null;

// var projects1 = col
// .Query()
// .Where(proj => proj.Plugins != null && proj.Plugins.Any(k => pluginsToLocate.Any(x => k.Name.Contains(x, StringComparison.InvariantCultureIgnoreCase))))
// .Select(p => p)
// .ToEnumerable();

// var projects2 = col
// .Query()
// .Where(proj => proj.Plugins.Where(plugin => pluginsToLocate.Contains(plugin.Name)).Any())
// .Select(p => p)
// .ToEnumerable();

// var projects3 = col
// .Query()
// .Where(proj =>
// proj.Plugins.Where(plugin =>
// pluginsToLocate.Any(p => p.Contains(plugin.Name, StringComparison.InvariantCultureIgnoreCase))
// ).Any()
// )
// .Select(p => p)
// .ToEnumerable();

// var projects4 = col
// .Include(x => x.Plugins)
// .FindAll()
// .Where(p => p.Plugins.Intersect(pluginsToLocate))

// var pluginToLocate = pluginsToLocate[0];
// var col = liteDb.GetCollection<LiveProject>("LiveProject");

// var query = @"SELECT { $.*, $.Plugins[*] FROM LiveProject } WHERE $.Plugins[*].Title LIKE '%" + pluginToLocate + "%'";
// var s = liteDb.Execute(query).ToList();

// var res = col.Query()
// .Where(proj => proj.Plugins.Any(p => p.Key.Contains(pluginToLocate, StringComparison.InvariantCultureIgnoreCase)).Any())
// .Select(x => x);

// return res.ToEnumerable();

// return null;

0 comments on commit e09c2e8

Please sign in to comment.