Implement a simple database system for managing quotes in Go. The system should include functionality to create, retrieve, list, and close a database. The system will involve a data structure to handle quotes, which consist of an author, text, and source.
Requirements:
Database Structure (DB):
Create a DB struct that encapsulates methods for interacting with the database.
The DB struct should have a method Open(path string) (*DB, error) to create a new database or open an existing one.
The DB struct should have a method Close() error to properly close the database and free resources.
Quote Structure (Quote):
Define a Quote struct that contains:
Author string
Text string
Source string
Database Operations:
Implement a method Create(quote *Quote) error that adds a quote to the database. If a quote by the same author already exists, it should return an error.
Implement a method Get(author string) (*Quote, error) that fetches a quote by its author. If no quote is found, it should return an error.
Implement a method List() ([]*Quote, error) that retrieves all quotes, sorted alphabetically by the author's name.
Testing:
Ensure that your implementation passes the provided test cases in quotes package. Pay attention to the creation of new quotes, updating existing ones, and listing them in sorted order.
Deliverables:
The code must be placed in the /app/ directory.
Ensure proper error handling and resource management, including cleanup (e.g., removing test data after tests).
Important: declare your solution in package quotes (the test file uses package quotes, so the implementation must use the matching package name).