Bird
0
0

Which of the following is the correct way to import and create a Database instance using the databases library?

easy📝 Syntax Q3 of 15
FastAPI - Database Integration
Which of the following is the correct way to import and create a Database instance using the databases library?
Aimport databases database = databases.Database()
Bfrom databases import Database database = Database("sqlite:///./test.db")
Cfrom fastapi import Database database = Database("sqlite:///./test.db")
Dfrom databases import Database database = Database()
Step-by-Step Solution
Solution:
  1. Step 1: Check correct import statement

    The Database class is imported from the databases library, not from FastAPI.
  2. Step 2: Verify correct instantiation

    The Database instance requires the database URL as a string argument during creation.
  3. Final Answer:

    from databases import Database\ndatabase = Database("sqlite:///./test.db") -> Option B
  4. Quick Check:

    Import and instantiate with URL = B [OK]
Quick Trick: Import Database from databases and pass URL on creation [OK]
Common Mistakes:
MISTAKES
  • Importing Database from FastAPI
  • Not passing database URL when creating instance
  • Calling Database() without arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes