@@ -22,14 +22,17 @@ insert into movie_budget values ('{"movie_id": 1,"movie_title":"Avatar","movie_y
2222insert into movie_budget values (' {"movie_id": 2,"movie_title":"Ghostbusters II","movie_year": 1989,
2323"sku":"FWT19789","runtime": 104,"cast":["Bill Murray","Sigourney Weaver"],
2424"genre":["Fantasy","Sci-Fi","Thriller","Comedy"]}' );
25+ commit ;
2526-- see the JSON collection that has been created along with the ability to query it
2627select * from movie_budget;
2728-- Let's add budget information to the movies
2829update movie_budget set data= JSON_TRANSFORM(data, set ' $.budgetUnit' = ' Million USD' , set ' $.budget' = 1000000 );
30+ commit ;
2931select json_value(data, ' $.movie_id' ) movie_id,json_value(data,' $.budget' ) budget from movie_budget;
3032-- Change the budget for one of the movies
3133update movie_budget set data= JSON_TRANSFORM(data, set ' $.budget' = (json_value(data,' $.budget' ) * 2 ))
3234where JSON_VALUE(data,' $.movie_id' )= 2 ;
35+ commit ;
3336select json_value(data, ' $.movie_id' ) movie_id,json_value(data,' $.budget' ) budget from movie_budget;
3437
3538-- JSON Duality
@@ -69,8 +72,9 @@ customer @insert @update @delete
6972 LastName : last_name,
7073 age : age,
7174 yrs_customer : yrs_customer
72- streams : streams
75+ streams : streams @insert @ update @ delete
7376 [{
77+ cust_id : cust_id
7478 day_id : day_id
7579 genre_id : genre_id
7680 movie_id : movie_id
@@ -82,6 +86,27 @@ select * from customer_streams_dv;
8286select * from customer_streams_dv
8387where JSON_VALUE(data,' $.streams.genre_id' )= 19 ;
8488
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+
85110/* With the JSON Collections and JSON Duality Views you can use API calls with GET and PUT to work
86111with the JSON in the database. We have just shown here SQL access to the JSON. */
87112
0 commit comments