FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
drupaljs/sql/functions.sql at main · ruvnet/drupaljs · GitHub
ruvnet
/
drupaljs
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
38
Code
Issues
2
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
drupaljs
/
sql
/
functions.sql
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (45 loc) · 1.27 KB
Breadcrumbs
drupaljs
/
sql
/
functions.sql
Copy path
File metadata and controls
50 lines (45 loc) · 1.27 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
--
Custom functions for Drupal.js
--
Function to update the 'updated_at' timestamp
CREATE OR REPLACE
FUNCTION
update_timestamp
()
RETURNS TRIGGER
AS
$$
BEGIN
NEW
.
updated_at
=
CURRENT_TIMESTAMP
;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
--
Function to get all child terms of a given term
CREATE OR REPLACE
FUNCTION
get_child_terms
(parent_term_id UUID)
RETURNS TABLE (id UUID, name
TEXT
, depth
INT
)
AS
$$
WITH RECURSIVE term_tree
AS
(
SELECT
id, name,
0
AS
depth
FROM
terms
WHERE
id
=
parent_term_id
UNION ALL
SELECT
t
.
id
,
t
.
name
,
tt
.
depth
+
1
FROM
terms t
JOIN
term_tree tt
ON
t
.
parent_id
=
tt
.
id
)
SELECT
id, name, depth
FROM
term_tree
WHERE
depth
>
0
;
$$ LANGUAGE sql;
--
Function to get the full path of a menu item
CREATE OR REPLACE
FUNCTION
get_menu_item_path
(item_id UUID)
RETURNS
TEXT
AS
$$
DECLARE
path
TEXT
:
=
'
'
;
current_id UUID :
=
item_id;
current_title
TEXT
;
BEGIN
WHILE current_id
IS NOT NULL
LOOP
SELECT
title, parent_id
INTO current_title, current_id
FROM
menu_items
WHERE
id
=
current_id;
IF
path
=
'
'
THEN
path
:
=
current_title;
ELSE
path
:
=
current_title
||
'
>
'
||
path
;
END IF;
END LOOP;
RETURN
path
;
END;
$$ LANGUAGE plpgsql;
Back
|
FazBrowse Home
|
New Git URL