Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
lektor
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
703324ef
Vérifiée
Valider
703324ef
rédigé
Il y a 2 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
DB: Begin to implement search by a struct with builder like patterns.
parent
c0709481
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
src/rust/lektor_db/src/connexion.rs
+79
-10
79 ajouts, 10 suppressions
src/rust/lektor_db/src/connexion.rs
src/rust/lektor_db/src/uri.rs
+1
-1
1 ajout, 1 suppression
src/rust/lektor_db/src/uri.rs
avec
80 ajouts
et
11 suppressions
src/rust/lektor_db/src/connexion.rs
+
79
−
10
Voir le fichier @
703324ef
use
crate
::{
models
::
*
,
types
::
*
,
uri
::
LktUri
,
*
};
use
crate
::{
models
::
*
,
types
::
*
,
uri
::
LktUri
,
*
};
use
hashbrown
::
HashMap
;
use
hashbrown
::
HashMap
;
use
kurisu_api
::
v1
as
api_v1
;
use
kurisu_api
::
v1
as
api_v1
;
use
smallstring
::
SmallString
;
/// Create a connexion to a database and run automatically the migrations.
/// Create a connexion to a database and run automatically the migrations.
fn
establish_connection
(
path
:
impl
AsRef
<
str
>
)
->
Result
<
SqliteConnection
,
String
>
{
fn
establish_connection
(
path
:
impl
AsRef
<
str
>
)
->
Result
<
SqliteConnection
,
String
>
{
...
@@ -17,6 +18,24 @@ pub struct LktDatabaseConnection {
...
@@ -17,6 +18,24 @@ pub struct LktDatabaseConnection {
sqlite
:
SqliteConnection
,
sqlite
:
SqliteConnection
,
}
}
/// Builder to realize a search operation in the database.
#[derive(Debug,
Default,
Clone,
PartialEq,
Eq)]
pub
struct
LktDatabaseSearch
{
search_type
:
LktDatabaseSearchType
,
uri
:
LktUri
,
range
:
Option
<
Range
<
usize
>>
,
}
/// A searcg type, to determine which table we are search.
#[derive(Debug,
Default,
Clone,
PartialEq,
Eq)]
pub
enum
LktDatabaseSearchType
{
Playlist
(
SmallString
),
History
,
#[default]
Database
,
}
/// Load the diesel DSL for a given table. With the loaded dsl execute the
/// Load the diesel DSL for a given table. With the loaded dsl execute the
/// expression...
/// expression...
macro_rules!
with_dsl
{
macro_rules!
with_dsl
{
...
@@ -38,6 +57,30 @@ macro_rules! fuzzy {
...
@@ -38,6 +57,30 @@ macro_rules! fuzzy {
(
@
inner
$x:ident
$y:ident
$
(
$xs:ident
)
+
)
=>
{
fuzzy!
(
@
inner
$x
$y
)
.concat
(
fuzzy!
(
@
inner
$
(
$xs
)
+
))
};
(
@
inner
$x:ident
$y:ident
$
(
$xs:ident
)
+
)
=>
{
fuzzy!
(
@
inner
$x
$y
)
.concat
(
fuzzy!
(
@
inner
$
(
$xs
)
+
))
};
}
}
impl
LktDatabaseSearch
{
pub
fn
new
(
search_type
:
LktDatabaseSearchType
)
->
Self
{
Self
{
search_type
,
..
Default
::
default
()
}
}
pub
fn
search_type
(
mut
self
,
ty
:
LktDatabaseSearchType
)
->
Self
{
self
.search_type
=
ty
;
self
}
pub
fn
range
(
mut
self
,
range
:
Range
<
usize
>
)
->
Self
{
self
.range
=
Some
(
range
);
self
}
pub
fn
uri
(
mut
self
,
uri
:
LktUri
)
->
Self
{
self
.uri
=
uri
;
self
}
}
impl
LktDatabaseConnection
{
impl
LktDatabaseConnection
{
/// Create a new database connexion.
/// Create a new database connexion.
pub
fn
try_new
(
path
:
impl
AsRef
<
Path
>
)
->
LktDatabaseResult
<
Self
>
{
pub
fn
try_new
(
path
:
impl
AsRef
<
Path
>
)
->
LktDatabaseResult
<
Self
>
{
...
@@ -201,17 +244,43 @@ impl LktDatabaseConnection {
...
@@ -201,17 +244,43 @@ impl LktDatabaseConnection {
}}
}}
}
}
/// Search the history by URIs. We return the local ids.
/// Search the database with the built search. We return the local ids.
pub
fn
search_history
(
&
mut
self
,
_uri
:
LktUri
)
->
LktDatabaseResult
<
Vec
<
i64
>>
{
pub
fn
search
(
&
mut
self
,
search
:
LktDatabaseSearch
)
->
LktDatabaseResult
<
Vec
<
i64
>>
{
todo!
()
// We begin by filtering the database, for KaraMaker, Language, Search
}
// and Playlist we get all non virtual karas, because we are joining
// other tables we can't use [into_boxed]...
let
karas
=
match
search
.uri
{
LktUri
::
Id
(
uri_id
)
=>
with_dsl!
{
kara
=>
kara
.filter
(
id
.is
(
uri_id
))
.filter
(
is_virtual
.is
(
false
))
.into_boxed
()
},
LktUri
::
Origin
(
ref
uri_origin
)
=>
with_dsl!
{
kara
=>
kara
.filter
(
song_origin
.is
(
uri_origin
.as_str
()))
.filter
(
is_virtual
.is
(
false
))
.into_boxed
()
},
LktUri
::
Type
(
ref
uri_type
)
=>
with_dsl!
(
kara
=>
kara
.filter
(
song_type
.is
(
uri_type
.as_str
()))
.filter
(
is_virtual
.is
(
false
))
.into_boxed
()
),
LktUri
::
FuzzySearch
(
_
)
=>
with_dsl!
{
kara
=>
kara
.into_boxed
()
},
LktUri
::
KaraMaker
(
_
)
|
LktUri
::
Language
(
_
)
|
LktUri
::
Search
(
_
)
|
LktUri
::
Playlist
(
_
)
|
LktUri
::
Any
=>
with_dsl!
{
kara
=>
kara
.filter
(
is_virtual
.is
(
false
))
.into_boxed
()
},
};
/// Search the given playlist by URIs. We return the local ids.
pub
fn
search_playlist
<
S
:
AsRef
<
str
>>
(
&
mut
self
,
_playlist
:
S
,
_uri
:
LktUri
,
)
->
LktDatabaseResult
<
Vec
<
i64
>>
{
todo!
()
todo!
()
}
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/rust/lektor_db/src/uri.rs
+
1
−
1
Voir le fichier @
703324ef
use
lektor_c_compat
::
rs
::{
LktCUri
,
LktUriField
};
use
lektor_c_compat
::
rs
::{
LktCUri
,
LktUriField
};
use
smallstring
::
SmallString
;
use
smallstring
::
SmallString
;
#[derive(Debug,
Clone,
Default)]
#[derive(Debug,
Clone,
Default
,
PartialEq,
Eq
)]
pub
enum
LktUri
{
pub
enum
LktUri
{
/// The id of the kara must match the URI.
/// The id of the kara must match the URI.
Id
(
i64
),
Id
(
i64
),
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter