Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7860172
query-or.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
query-or.ts
View Options
import
Query
from
"./query.js"
;
import
type
{
QueryStage
}
from
"./query-stage.js"
;
import
type
{
MatchBody
}
from
"./query-stage.js"
;
import
QueryStep
,
{
Lookup
,
Match
}
from
"./query-step.js"
;
import
type
{
SQLPreparedStatement
}
from
"./query-base.js"
;
export
default
class
Or
extends
Query
{
lookup_steps
:
QueryStep
[]
=
[];
queries
:
Query
[];
constructor
(...
queries
:
Query
[])
{
super
();
this
.
queries
=
queries
;
for
(
const
query
of
queries
)
{
this
.
addQuery
(
query
);
}
}
addQuery
(
query
:
Query
)
:
void
{
const
steps
=
query
.
dump
();
this
.
lookup_steps
.
push
(
...(
steps
.
filter
((
step
)
=>
step
instanceof
Lookup
)
as
Lookup
[])
);
const
match_stage_bodies
=
steps
.
filter
((
step
)
=>
step
instanceof
Match
)
.
map
((
match
:
Match
)
=>
match
.
body
);
if
(
match_stage_bodies
.
length
)
{
const
match_stage
:
MatchBody
=
match_stage_bodies
.
length
>
1
?
{
$and
:
match_stage_bodies
}
:
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
match_stage_bodies
[
0
]
!
;
this
.
steps
.
push
(
new
Match
(
match_stage
));
}
}
dump
()
:
QueryStep
[]
{
return
this
.
lookup_steps
.
concat
(
new
Match
({
$or
:
this
.
_getMatchExpressions
()
})
);
}
toPipeline
()
:
QueryStage
[]
{
const
lookups
=
this
.
lookup_steps
.
map
((
step
)
=>
step
.
toPipeline
())
.
reduce
((
acc
,
cur
)
=>
acc
.
concat
(
cur
),
[]);
return
lookups
.
concat
({
$match
:
{
$or
:
this
.
_getMatchExpressions
()
}
});
}
toPreparedStatement
()
:
SQLPreparedStatement
{
const
compiledStatements
=
this
.
queries
.
map
((
query
)
=>
query
.
toPreparedStatement
()
);
const
parameters
=
compiledStatements
.
flatMap
(
(
statement
)
=>
statement
.
parameters
);
const
sqlExpressions
=
compiledStatements
.
map
(
(
statement
)
=>
statement
.
where
);
const
sqlJoins
=
compiledStatements
.
flatMap
(
(
statement
)
=>
statement
.
join
);
let
counter
=
0
;
return
{
where
:
`(
${
sqlExpressions
.
join
(
" OR "
)
}
)`
.
replace
(
/\$[0-9]+/g
,
()
=>
`$
${
++
counter
}
`
),
join
:
sqlJoins
,
parameters
,
};
}
_getMatchExpressions
()
:
MatchBody
[]
{
return
this
.
steps
.
filter
((
step
)
=>
step
instanceof
Match
)
.
map
((
step
)
=>
step
.
body
as
MatchBody
);
}
prefix
(
prefix
:
string
)
:
this
{
super
.
prefix
(
prefix
);
this
.
lookup_steps
=
this
.
lookup_steps
.
map
((
step
)
=>
step
.
prefix
(
prefix
)
);
return
this
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, Aug 13, 17:16 (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
876834
Default Alt Text
query-or.ts (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment