|
| 1 | +with |
| 2 | + usersJson := to_json('[ |
| 3 | + { |
| 4 | + |
| 5 | + "realFirstName": "Bilbo", |
| 6 | + "realLastName": "Baggins", |
| 7 | + "about": "A halfling from the Shire", |
| 8 | + "roles": ["ProjectManager"], |
| 9 | + "title": "Halfling Manager", |
| 10 | + "education": [ |
| 11 | + { |
| 12 | + "degree": "Bachelors", |
| 13 | + "major": "Unlikely Heroics", |
| 14 | + "institution": "Shire University" |
| 15 | + } |
| 16 | + ] |
| 17 | + }, |
| 18 | + { |
| 19 | + |
| 20 | + "realFirstName": "Frodo", |
| 21 | + "realLastName": "Baggins", |
| 22 | + "about": "The nephew of a halfling from the Shire", |
| 23 | + "roles": ["FinancialAnalyst"], |
| 24 | + "title": "Jewlery Steward", |
| 25 | + "education": [ |
| 26 | + { |
| 27 | + "degree": "Bachelors", |
| 28 | + "major": "Unlikely Heroics", |
| 29 | + "institution": "Shire University" |
| 30 | + }, |
| 31 | + { |
| 32 | + "degree": "Masters", |
| 33 | + "major": "Determination Tactics", |
| 34 | + "institution": "Shire University" |
| 35 | + } |
| 36 | + ] |
| 37 | + }, |
| 38 | + { |
| 39 | + |
| 40 | + "realFirstName": "Gandalf", |
| 41 | + "realLastName": "The Gray", |
| 42 | + "about": "A wizard of Ainur", |
| 43 | + "roles": ["Controller"], |
| 44 | + "title": "Mithrandir of Middle Earth", |
| 45 | + "education": [ |
| 46 | + { |
| 47 | + "degree": "Doctorate", |
| 48 | + "major": "Wizardry Proper", |
| 49 | + "institution": "Timeless Halls" |
| 50 | + } |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + |
| 55 | + "realFirstName": "Samwise", |
| 56 | + "realLastName": "Gamgee", |
| 57 | + "about": "A gardening halfing.", |
| 58 | + "roles": ["ConsultantManager"], |
| 59 | + "title": "Son of the Gaffer", |
| 60 | + "education": [ |
| 61 | + { |
| 62 | + "degree": "Bachelors", |
| 63 | + "major": "Arboriculture", |
| 64 | + "institution": "Shire University" |
| 65 | + } |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + |
| 70 | + "realFirstName": "Meriadoc", |
| 71 | + "realLastName": "Brandybuck", |
| 72 | + "about": "A halfling friend", |
| 73 | + "roles": ["Controller"], |
| 74 | + "title": "Holdwine of the Shire", |
| 75 | + "education": [ |
| 76 | + { |
| 77 | + "degree": "Bachelors", |
| 78 | + "major": "Unexpected Bravery", |
| 79 | + "institution": "Shire University" |
| 80 | + } |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + |
| 85 | + "realFirstName": "Peregrin", |
| 86 | + "realLastName": "Took", |
| 87 | + "about": "A halfing of mild mischief.", |
| 88 | + "roles": ["RegionalDirector"], |
| 89 | + "title": "Master of Curiousity", |
| 90 | + "education": [ |
| 91 | + { |
| 92 | + "degree": "Bachelors", |
| 93 | + "major": "Culinary Arts", |
| 94 | + "institution": "Shire University" |
| 95 | + } |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + |
| 100 | + "realFirstName": "Aragorn", |
| 101 | + "realLastName": "Son of Arathorn", |
| 102 | + "about": "A human of the Dunedain.", |
| 103 | + "roles": ["Leadership"], |
| 104 | + "title": "King of Gondor and Arnor", |
| 105 | + "education": [ |
| 106 | + { |
| 107 | + "degree": "Bachelors", |
| 108 | + "major": "Leadership", |
| 109 | + "institution": "Rivendell University" |
| 110 | + }, |
| 111 | + { |
| 112 | + "degree": "Masters", |
| 113 | + "major": "Swordsmanship", |
| 114 | + "institution": "Rivendell University" |
| 115 | + } |
| 116 | + ] |
| 117 | + } |
| 118 | + ]'), |
| 119 | + users := ( |
| 120 | + for user in json_array_unpack(usersJson) |
| 121 | + union ( |
| 122 | + (select User filter .email = <str>user['email']) ?? |
| 123 | + (insert User { |
| 124 | + email := <str>user['email'], |
| 125 | + realFirstName := <str>user['realFirstName'], |
| 126 | + realLastName := <str>user['realLastName'], |
| 127 | + phone := '555-555-5555', |
| 128 | + about := <str>user['about'], |
| 129 | + roles := <str>json_array_unpack(user['roles']), |
| 130 | + title := <str>user['title'], |
| 131 | + education := ( |
| 132 | + for edu in json_array_unpack(user['education']) |
| 133 | + union ( |
| 134 | + insert User::Education { |
| 135 | + degree := <str>edu['degree'], |
| 136 | + major := <str>edu['major'], |
| 137 | + institution := <str>edu['institution'] |
| 138 | + } |
| 139 | + ) |
| 140 | + ) |
| 141 | + }) |
| 142 | + ) |
| 143 | + ), |
| 144 | + new := (select users filter .createdAt = datetime_of_statement()) |
| 145 | +select { `Added Users` := new.realFirstName ++ ' ' ++ new.realLastName } |
| 146 | +filter count(new) > 0; |
0 commit comments