How to use run_query method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

orders.py

Source:orders.py Github

copy

Full Screen

...15 16 if len(params.keys()) == 1:17 token = params.get('token')18 19 client_validity = run_query('SELECT token, client_id FROM client_session WHERE token=?', [token])20 21 restaurant_validity = run_query('SELECT token, restaurant_id FROM restaurant_session WHERE token=?', [token])22 23 if client_validity != []:24 client_validity_response = client_validity[0]25 if client_validity_response[0] == token:26 client_id = client_validity_response[1]27 28 all_user_orders = run_query('SELECT * FROM orders WHERE client_id=?', [client_id])29 30 all_orders = []31 for item in all_user_orders:32 order = order_dictionary_query(item)33 all_orders.append(order)34 return jsonify(all_orders)35 36 if restaurant_validity != []:37 restaurant_validity_response = restaurant_validity[0]38 if restaurant_validity_response[0] == token:39 restaurant_id = restaurant_validity_response[1]40 41 all_rest_orders = run_query('SELECT * FROM orders WHERE restaurant_id=?', [restaurant_id])42 43 all_orders = []44 for item in all_rest_orders:45 order = order_dictionary_query(item)46 all_orders.append(order)47 return jsonify(all_orders)48 49 if len(params.keys()) == 2:50 51 token = params.get('token')52 order_id = params.get('order_id')53 54 client_validity = run_query('SELECT token, client_id FROM client_session WHERE token=?', [token])55 56 restaurant_validity = run_query('SELECT token, restaurant_id FROM restaurant_session WHERE token=?', [token])57 58 if client_validity != []:59 client_validity_response = client_validity[0]60 if client_validity_response[0] == token:61 client_id = client_validity_response[1]62 specific_order = run_query('SELECT * FROM orders WHERE client_id=? AND id=?', [client_id, order_id])63 64 order_info = []65 for item in specific_order:66 order = order_dictionary_query(item)67 order_info.append(order)68 return jsonify(order_info)69 70 71 if restaurant_validity != []:72 restaurant_validity_response = restaurant_validity[0]73 if restaurant_validity_response[0] == token:74 75 restaurant_id = restaurant_validity_response[1]76 specific_order = run_query('SELECT * FROM orders WHERE restaurant_id=? AND id=?', [restaurant_id, order_id])77 78 order_info = []79 for item in specific_order:80 order = order_dictionary_query(item)81 order_info.append(order)82 return jsonify(order_info)83 84 else:85 return jsonify('Incorrect keys submitted'), 40086 else:87 return jsonify('Error, invalid amount of data submitted'), 40088 89@app.post('/api/orders')90def orders_post():91 # parameter for token -- get the client id from the token92 params = request.args93 token = params.get('token')94 data = request.json95 rest_id = data.get('rest_id')96 items = data.get('items')97 98 if len(data.keys()) == 2 and {'items', 'rest_id'}:99 100 if token != None:101 token_valid = run_query('SELECT token, client_id FROM client_session WHERE token=?', [token])102 103 104 token_valid_response = token_valid[0]105 client_id = token_valid_response[1]106 response = token_valid_response[0]107 108 if response == token:109 110 order_id = order_query('INSERT INTO orders (client_id, restaurant_id) VALUES (?,?)',[client_id, rest_id])111 112 113 114 if len(items) == 1:115 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])116 117 elif len(items) == 2:118 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])119 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])120 121 elif len(items) == 3:122 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])123 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])124 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[2], order_id])125 elif len(items) == 4:126 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])127 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])128 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[2], order_id])129 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[3], order_id])130 elif len(items) == 5:131 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])132 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])133 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[2], order_id])134 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[3], order_id])135 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[4], order_id])136 elif len(items) == 6:137 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])138 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])139 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[2], order_id])140 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[3], order_id])141 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[4], order_id])142 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[5], order_id])143 elif len(items) == 7:144 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])145 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])146 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[2], order_id])147 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[3], order_id])148 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[4], order_id])149 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[5], order_id])150 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[6], order_id])151 elif len(items) == 8:152 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])153 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])154 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[2], order_id])155 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[3], order_id])156 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[4], order_id])157 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[5], order_id])158 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[6], order_id])159 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[7], order_id])160 elif len(items) == 9:161 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])162 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])163 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[2], order_id])164 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[3], order_id])165 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[4], order_id])166 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[5], order_id])167 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[6], order_id])168 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[7], order_id])169 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[8], order_id])170 elif len(items) == 10:171 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])172 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])173 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[2], order_id])174 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[3], order_id])175 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[4], order_id])176 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[5], order_id])177 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[6], order_id])178 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[7], order_id])179 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[8], order_id])180 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[9], order_id])181 elif len(items) == 11:182 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[0], order_id])183 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[1], order_id])184 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[2], order_id])185 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[3], order_id])186 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[4], order_id])187 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[5], order_id])188 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[6], order_id])189 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[7], order_id])190 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[8], order_id])191 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[9], order_id])192 run_query('INSERT INTO order_menu_item (menu_id, order_id) VALUES (?,?)', [items[10], order_id])193 194 return jsonify("Order Created"), 201195 196 else:197 return jsonify('ERROR, submitted token is not a valid client_session token'), 401198 else:199 return jsonify('ERROR, a client_session token is required to request an order'), 401200 201 else:202 return jsonify('Incorrect keys submitted'), 422203 204@app.patch('/api/orders')205def orders_patch():206 # WHAT is needed for request - has to be seen for either restaurant or client207 # parameter for token -- get the restaurant or client id from the token208 # If client is using, options are cancelOrder209 # If restaurant is using, options are confirmOrder or completeOrder210 211 params = request.args212 data = request.json213 if len(params.keys()) == 2:214 token = params.get('token')215 216 client_validity = run_query('SELECT token, client_id FROM client_session WHERE token=?', [token])217 218 restaurant_validity = run_query('SELECT token, restaurant_id FROM restaurant_session WHERE token=?', [token])219 220 if client_validity != []:221 client_validity_response = client_validity[0]222 if client_validity_response[0] == token:223 client_id = client_validity_response[1]224 order_id = params.get('order_id')225 order_id_int = int(order_id)226 227 order_verification = run_query('SELECT id FROM orders WHERE client_id=? AND id=?', [client_id, order_id_int])228 229 order_verification_response = order_verification[0]230 231 if order_verification_response[0] == order_id_int:232 is_cancelled = data.get('is_cancelled')233 if is_cancelled == "True":234 cancel_order = 1235 run_query('UPDATE orders SET is_cancelled=? WHERE order_id=?', [cancel_order, order_id])236 return jsonify('Order Cancelled')237 238 if restaurant_validity != []:239 restaurant_validity_response = restaurant_validity[0]240 if restaurant_validity_response[0] == token:241 rest_id = restaurant_validity_response[1]242 order_id = params.get('order_id')243 order_id_int = int(order_id)244 245 order_verification = run_query('SELECT id FROM orders WHERE restaurant_id=? AND id=?', [rest_id, order_id_int])246 order_verification_response = order_verification[0]247 if order_verification_response[0] == order_id_int:248 is_confirmed = data.get('is_confirmed')249 250 if is_confirmed != None:251 if is_confirmed == "True":252 confirm_order = 1253 254 run_query('UPDATE orders SET is_confirmed=? WHERE id=?', [confirm_order, order_id_int])255 return jsonify('Order Confirmed')256 257 is_complete = data.get('is_complete')258 259 if is_complete != None:260 if is_complete == "True":261 is_confirmed = 0262 complete_order = 1263 run_query('UPDATE orders SET is_confirmed=? WHERE id=?', [is_confirmed, order_id_int])264 run_query('UPDATE orders SET is_complete=? WHERE id=?', [complete_order, order_id_int])265 return jsonify('Order has been completed')266 267 else:268 return jsonify('ERROR')...

Full Screen

Full Screen

database.py

Source:database.py Github

copy

Full Screen

...10def disconnect_db():11 global session12 if session:13 session.close()14def run_query(file, command=''):15 connect_db()16 res = session.execute(17 'xquery \n' + open(os.path.join(STATICFILES_DIRS[0], "queries", file), 'r').read() + '\n' + command)18 disconnect_db()19 return res20def list_all_players():21 res = run_query("ListAllPlayers.xq")22 return res23def order_players_pos(pos):24 res = run_query('OrderPlayersOverallArgument.xq', 'local:playersByPosition("{}")'.format(pos))25 return res26def list_players_ord():27 res = run_query('ListAllPlayersByOverall.xq')28 return res29def get_player_by_id(player_id):30 res = run_query('GetPlayerById.xq', 'local:getPlayerById({})'.format(player_id))31 return res32def get_round_results(season, comp, round):33 res = run_query('RoundResults.xq', 'local:RoundResults({}, {} ,{})'.format(season, comp, round))34 return res35def get_team_home_wins(season, comp, team):36 res = run_query('HomeWins.xq', 'local:HomeWins("{}", {} ,{})'.format(season, comp, team))37 return res38def get_team_away_wins(season, comp, team):39 res = run_query('AwayWins.xq', 'local:AwayWins("{}", {} ,{})'.format(season, comp, team))40 return res41def get_team_home_losses(season, comp, team):42 res = run_query('HomeLosses.xq', 'local:HomeLosses("{}", {} ,{})'.format(season, comp, team))43 return res44def get_team_away_losses(season, comp, team):45 res = run_query('AwayLosses.xq', 'local:AwayLosses("{}", {} ,{})'.format(season, comp, team))46 return res47def get_team_draws(season, comp, team):48 res = run_query('Draws.xq', 'local:Draws("{}", {} ,{})'.format(season, comp, team))49 return res50def get_team_info(team):51 res = run_query('BasicTeamInfo.xq', 'local:TeamInfo({})'.format(team))52 return res53def get_team_players(team):54 res = run_query('TeamPlayers.xq', 'local:TeamPlayers({})'.format(team))55 return res56def get_team_best_player(team):57 res = run_query('BestPlayerInTeam.xq', 'local:BestPlayer({})'.format(team))58 return res59def get_player_by_name(player):60 res = run_query('PlayerInfoByName.xq', 'local:PlayerInfoByName({})'.format(player))61 return res62def get_most_used_player(team):63 res = run_query('StartingEleven.xq', 'local:StartingEleven({})'.format(team))64 root = ET.fromstringlist(res)65 dict = {}66 for c in root:67 players = str(c.text).split(';')68 for player in players:69 if len(player) > 2:70 if player in dict and player != 'None':71 dict[player] += 172 else:73 dict[player] = 174 mostUsedVal = max(dict.values())75 return [p for p in dict if dict[p] == mostUsedVal]76def get_match_info(season, comp, matchID):77 res = run_query('MatchInfo.xq', 'local:MatchInfo({}, {} ,{})'.format(season, comp, matchID))78 return res79def get_match_by_id(match_id):80 res = run_query("GetMatchById.xq", 'local:GetMatchById({})'.format(match_id))81 return res82def get_match_events(match_id):83 res = run_query("MatchEvents.xq", 'local:MatchEvents({})'.format(match_id))84 return res85def get_index_info():86 res = run_query('IndexInfo.xq')87 return res88def get_all_teams_info():89 res = run_query('AllTeamsInfo.xq')90 return res91def get_teams_from_comp(comp):92 res = run_query('LeagueTeamsByID.xq', 'local:LeagueTeamsByID({})'.format(comp))93 return res94def get_calendar_for_index(comp, season):95 res = run_query('ListCalendar.xq', 'local:ListCalendar({}, {})'.format(comp, season))96 return res97def get_plantel(team):98 res = run_query('PlayersInTeam.xq', 'local:PlayersInTeam({})'.format(team))99 return res100def get_matches():101 res = run_query('ListMatches.xq')102 return res103def get_starting_eleven(season, comp, team):104 res = run_query('StartingEleven.xq', 'local:StartingEleven({}, {} ,{})'.format(season, comp, team))105 return res106def get_matches_league(league_id):107 res = run_query('AddBadgesMatchesLeague.xq', 'local:getMatches({})'.format(league_id))108 return res109def insert_match(matchID, league, season, homeTeam, awayTeam, date, stadium, round):110 res = run_query('InsertMatch.xq',111 'local:InsertMatch({}, {}, "{}", {}, {}, "{}", "{}", {})'.format(matchID, league, season, homeTeam,112 awayTeam, date, stadium, round))113 return res114def delete_match(matchID):115 res = run_query('DeleteMatch.xq', 'local:DeleteMatch({})'.format(matchID))116 return res117def edit_match(matchID, newLeagueID, newhomeTeam, newawayTeam, newdate, newstadium, newround):118 res = run_query('EditMatch.xq',119 'local:EditMatch({}, {}, {}, {}, "{}", "{}", {})'.format(matchID, newLeagueID, newhomeTeam, newawayTeam,120 newdate, newstadium, newround))121 return res122def get_match_events(matchID):123 res = run_query('MatchEvents.xq', 'local:MatchEvents({})'.format(matchID))124 return res125def match_players_photos(matchID):126 res = run_query('StartingElevenPhotosID.xq', 'local:PlayersPhotos({})'.format(matchID))127 return res128def get_home_Goals(season, comp, team):129 res = run_query('HomeGoals.xq', 'local:HomeGoals("{}", {} ,{})'.format(season, comp, team))130 return res131def get_away_Goals(season, comp, team):132 res = run_query('AwayGoals.xq', 'local:AwayGoals("{}", {} ,{})'.format(season, comp, team))...

Full Screen

Full Screen

MLDB-832-select_star.py

Source:MLDB-832-select_star.py Github

copy

Full Screen

...19 ['x1', 3, 0],20 ['x2', 4, 0],21 ['x3', 5, 0]])22ds1.commit()23def run_query(select, expected):24 """ run a query using `select` on and compare the (sorted) column names25 with the `expected` column names26 ex:27 select = 'a, c, b'28 expected = 'a b c'29 """30 expected = expected.split()31 out = mldb.query('SELECT {} FROM {}'.format(select, 'd1'))32 cols = sorted(out[0][1:])33 if cols != expected:34 mldb.log('{} != {}'.format(cols, expected))35 mldb.log('output was')36 mldb.log(out)37 assert False38 return out39# simple queries like in the doc40run_query('*',41 'a b c x1 x2 x3')42run_query('{*} as *',43 'a b c x1 x2 x3')44run_query('{*\n} as *',45 'a b c x1 x2 x3')46run_query('{{*} as *} as *',47 'a b c x1 x2 x3')48# following test case shows the bug from MLDB-120549run_query('{{*} as *\n} as *',50 'a b c x1 x2 x3')51run_query('a,b,c,x1',52 'a b c x1')53run_query('* EXCLUDING (a)',54 'b c x1 x2 x3')55run_query('* EXCLUDING (a,c)',56 'b x1 x2 x3')57run_query('* EXCLUDING (x*)',58 'a b c')59run_query('* EXCLUDING (a, x*)',60 'b c')61run_query('x* AS y*',62 'y1 y2 y3')63run_query('x* EXCLUDING(x3) AS y*',64 'y1 y2')65# not sure that's how this one should behave66run_query('a, a', 'a')67# simple using object(select ...)68run_query('{*} as z',69 'z.a z.b z.c z.x1 z.x2 z.x3')70run_query('{a,b} as z',71 'z.a z.b')72run_query('{x*} as z',73 'z.x1 z.x2 z.x3')74run_query('a,b,c, {x*} as z',75 'a b c z.x1 z.x2 z.x3')76# Now a few with functions77conf = {'type': 'sql.expression',78 'params': {79 'expression': '{x*} as z'80 }}81res = mldb.put('/v1/functions/xs_as_z', conf)82check_res(res, 201)83run_query('a,b,c, xs_as_z({x*}) as *',84 'a b c z.x1 z.x2 z.x3')85run_query('xs_as_z({*}) as *',86 'z.x1 z.x2 z.x3')87run_query('xs_as_z({*})[z] as *',88 'x1 x2 x3')89run_query('xs_as_z({*})[z] as z',90 'z.x1 z.x2 z.x3')91#run_query('xs_as_z({*})[z as *] as *',92# 'x1 x2 x3')93run_query('xs_as_z({*})[{z.x1, z.x2}] as *',94 'z.x1 z.x2')95run_query('xs_as_z({*}) as *', 'z.x1 z.x2 z.x3')96# here I'm "calling" the function twice in another function97res = mldb.put('/v1/functions/twice', {98 'type' : 'sql.expression',99 'params': {100 'expression': 'xs_as_z({x*})[z] as w,'101 'xs_as_z({x*})[z] as z'102 }})103check_res(res, 201)104run_query('twice({*}) as *',105 'w.x1 w.x2 w.x3 z.x1 z.x2 z.x3')106# same thing but once107res = mldb.put('/v1/functions/once', {108 'type' : 'sql.expression',109 'params': {110 'expression': 'xs_as_z({x*})[z] as w,'111 }})112check_res(res, 201)113run_query('once({*}) as *', 'w.x1 w.x2 w.x3')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful