FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/daslib/linq_fold_sql.das at master · feiyunwill/daScript · GitHub
feiyunwill
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
daslib
/
linq_fold_sql.das
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (50 loc) · 2.11 KB
Breadcrumbs
daScript
/
daslib
/
linq_fold_sql.das
Copy path
File metadata and controls
56 lines (50 loc) · 2.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
options
gen2
options
indenting
=
4
options
_comment_hygiene
=
true
module
linq_fold_sql
shared
public
//! linq_fold SQL source pass-through: ``extract_sql_source``. Lets ``_fold`` over a
//! ``db |> select_from(type<Row>)`` chain (where ``Row`` is a ``[sql_table]``/``[sql_view]``/
//! ``[sql_fts5]`` struct) re-dispatch the whole chain to the ``_sql`` macro instead of folding the
//! materialized full-table ``array<Row>`` in memory. There is no emitting adapter — ``_sql`` is a
//! complete parallel lowering; this module only recognizes the source. Companion to
//! ``daslib/linq_fold``; provider-neutral (matches the ``[sql_table]`` annotation, not a runner
//! type), so it loads unconditionally. See daslib/linq_fold.md.
require
daslib
/
linq_fold_common
public
require
daslib
/
ast_boost
require
daslib
/
ast
// True iff `sql_linq` (which defines the `_sql` macro) is in the current program. A consumer may
// require a provider boost (for `select_from`) without `daslib/sql_linq`; then we must NOT rewrite
// to `_sql` (it wouldn't resolve) — `_fold` falls back to the in-memory array path instead.
[
macro_function
]
def
sql_linq_loaded
(
prog
:
ProgramPtr
) :
bool
{
var
found
=
false
program_for_each_module
(
prog
)
$
(mod) {
if
(
mod
.
name
==
"sql_linq"
) {
found
=
true
}
}
return
found
}
def
private
is_sql_table_select
(
c
:
ExprCall
?) :
bool
{
if
(
c
.
_type
==
null
||
!
c
.
_type
.
isGoodArrayType
||
c
.
_type
.
firstType
==
null
)
return
false
let
st
=
c
.
_type
.
firstType
.
structType
if
(
st
==
null
)
return
false
for
(
annDecl
in
st
.
annotations
) {
if
(
annDecl
.
annotation
.
name
==
"sql_table"
||
annDecl
.
annotation
.
name
==
"sql_view"
||
annDecl
.
annotation
.
name
==
"sql_fts5"
)
return
true
}
return
false
}
[
macro_function
]
def
extract_sql_source
(
var
expr
:
Expression
?) :
ExprCall
? {
var
e
=
expr
while
(
e
!
=
null
&&
e
is
ExprCall
) {
var
c
=
e
as
ExprCall
if
(
get_call_short_name
(
c
)
==
"select_from"
) {
return
is_sql_table_select
(
c
) ?
c
:
null
}
if
(
empty
(
c
.
arguments
))
break
e
=
c
.
arguments
[0]
}
return
null
}
Back
|
FazBrowse Home
|
New Git URL