Complete the code to define a microservice with its own database.
class [1]Service: def __init__(self): self.database = DatabaseConnection('user_db')
The UserService manages user data and thus connects to the 'user_db' database.
Complete the code to route a request to the correct microservice based on the database decomposition.
def route_request(request): if request.type == 'order': return [1]Service.handle(request)
OrderService handles requests related to orders, so the routing directs order requests there.
Fix the error in the database access code for the Inventory microservice.
class InventoryService: def get_stock(self, item_id): return self.db.[1]('SELECT stock FROM inventory WHERE id = %s', item_id)
The execute method runs the SQL query; fetchall retrieves results. Here, execute is needed first.
Fill both blanks to correctly implement database decomposition with separate connections and queries.
class [1]Service: def __init__(self): self.db = DatabaseConnection('[2]_db')
PaymentService connects to 'user_db' in this example, showing database decomposition by service.
Fill all three blanks to implement a query filtering orders by status in the Order microservice.
def get_orders_by_status(self, status): query = "SELECT * FROM orders WHERE status [1] %s" self.db.[2](query, (status,)) return self.db.[3]()
The query uses '=' to filter by status, execute runs the query, and fetchall retrieves the results.