@@ -22,14 +22,17 @@ insert into movie_budget values ('{"movie_id": 1,"movie_title":"Avatar","movie_y
22
22
insert into movie_budget values (' {"movie_id": 2,"movie_title":"Ghostbusters II","movie_year": 1989,
23
23
"sku":"FWT19789","runtime": 104,"cast":["Bill Murray","Sigourney Weaver"],
24
24
"genre":["Fantasy","Sci-Fi","Thriller","Comedy"]}' );
25
+ commit ;
25
26
-- see the JSON collection that has been created along with the ability to query it
26
27
select * from movie_budget;
27
28
-- Let's add budget information to the movies
28
29
update movie_budget set data= JSON_TRANSFORM(data, set ' $.budgetUnit' = ' Million USD' , set ' $.budget' = 1000000 );
30
+ commit ;
29
31
select json_value(data, ' $.movie_id' ) movie_id,json_value(data,' $.budget' ) budget from movie_budget;
30
32
-- Change the budget for one of the movies
31
33
update movie_budget set data= JSON_TRANSFORM(data, set ' $.budget' = (json_value(data,' $.budget' ) * 2 ))
32
34
where JSON_VALUE(data,' $.movie_id' )= 2 ;
35
+ commit ;
33
36
select json_value(data, ' $.movie_id' ) movie_id,json_value(data,' $.budget' ) budget from movie_budget;
34
37
35
38
-- JSON Duality
@@ -69,8 +72,9 @@ customer @insert @update @delete
69
72
LastName : last_name,
70
73
age : age,
71
74
yrs_customer : yrs_customer
72
- streams : streams
75
+ streams : streams @insert @ update @ delete
73
76
[{
77
+ cust_id : cust_id
74
78
day_id : day_id
75
79
genre_id : genre_id
76
80
movie_id : movie_id
@@ -82,6 +86,27 @@ select * from customer_streams_dv;
82
86
select * from customer_streams_dv
83
87
where JSON_VALUE(data,' $.streams.genre_id' )= 19 ;
84
88
89
+ /* Now to insert a new record into customers and streams we can do that through the Duality View.
90
+ Here we select first from customer and from streams to show there is no value */
91
+ select * from customer where cust_id= 555 ;
92
+ select * from streams where cust_id= 555 ;
93
+ -- Now do an insert to the DV to add a new customer and add a stream
94
+ insert into customer_streams_dv values (' {
95
+ "_id" : 555,
96
+ "FirstName" : "Michelle",
97
+ "LastName" : "Jones",
98
+ "age" : 36,
99
+ "yrs_customer" : 0 ,
100
+ "streams" : [{
101
+ "day_id" : "2024-11-18T00:00:00",
102
+ "genre_id" : 19,
103
+ "movie_id" : 3694}]}' );
104
+
105
+ commit ;
106
+ select * from customer where cust_id= 555 ;
107
+ select * from streams where cust_id= 555 ;
108
+ -- now we have rows in both of the underlying relational tables
109
+
85
110
/* With the JSON Collections and JSON Duality Views you can use API calls with GET and PUT to work
86
111
with the JSON in the database. We have just shown here SQL access to the JSON. */
87
112
0 commit comments