Repository: duckdb/duckdb
File: src/include/duckdb/main/attached_database.hpp (C++)

Code before:
	const string &GetName() const {
		return name;
	}
	void SetName(const string &new_name) {
		name = new_name;
	}
	bool IsSystem() const;
	bool IsTemporary() const;
	bool IsReadOnly() const;
	bool IsInitialDatabase() const;
	void SetInitialDatabase();
	void SetReadOnlyDatabase();
	void OnDetach(ClientContext &context);
	RecoveryMode GetRecoveryMode() const {
		return recovery_mode;
	}
	AttachVisibility GetVisibility() const {
		return visibility;
	}
	string StoredPath() const;

	static bool NameIsReserved(const string &name);
	static string ExtractDatabaseName(const string &dbpath, FileSystem &fs);
	// Close an attached database, if its use count is 1.
	// Only call this in places where you know that the (last) shared pointer is about to go out of scope.
	static void CloseIfLastReference(shared_ptr<AttachedDatabase> &attached_db);

private:
	DatabaseInstance &db;
	unique_ptr<StoredDatabasePath> stored_database_path;
	unique_ptr<StorageManager> storage;
	unique_ptr<Catalog> catalog;
	unique_ptr<TransactionManager> transaction_manager;
	AttachedDatabaseType type;
	optional_ptr<Catalog> parent_catalog;
	optional_ptr<StorageExtension> storage_extension;
	RecoveryMode recovery_mode = RecoveryMode::DEFAULT;
	AttachVisibility visibility = AttachVisibility::SHOWN;
	bool is_initial_database = false;
	bool close = true;

private:
	//! Clean any (shared) resources held by the database.
	void Cleanup();
};

} // namespace duckdb


Review comment (suggestion):
Maybe this shouldn't be a reference now that I think about it. Passing in a reference could be unsafe - if this is the actual `shared_ptr<AttachedDatabase>` and we only have one reference to it in that function then we know for sure it will be destroyed after we leave the function which means the function is safe.

Code after:
	const string &GetName() const {
		return name;
	}
	void SetName(const string &new_name) {
		name = new_name;
	}
	bool IsSystem() const;
	bool IsTemporary() const;
	bool IsReadOnly() const;
	bool IsInitialDatabase() const;
	void SetInitialDatabase();
	void SetReadOnlyDatabase();
	void OnDetach(ClientContext &context);
	RecoveryMode GetRecoveryMode() const {
		return recovery_mode;
	}
	AttachVisibility GetVisibility() const {
		return visibility;
	}
	const unordered_map<string, Value> &GetAttachOptions() const {
		return attach_options;
	}
	string StoredPath() const;

	static bool NameIsReserved(const string &name);
	static string ExtractDatabaseName(const string &dbpath, FileSystem &fs);
	// Invoke Close() on an attached database, if its use count is 1.
	// Only call this in places where you know that the (last) shared pointer is about to go out of scope.
	static void InvokeCloseIfLastReference(shared_ptr<AttachedDatabase> &attached_database);

private:
	DatabaseInstance &db;
	unique_ptr<StoredDatabasePath> stored_database_path;
	unique_ptr<StorageManager> storage;
	unique_ptr<Catalog> catalog;
	unique_ptr<TransactionManager> transaction_manager;
	AttachedDatabaseType type;
	optional_ptr<Catalog> parent_catalog;
	optional_ptr<StorageExtension> storage_extension;
	RecoveryMode recovery_mode = RecoveryMode::DEFAULT;
	AttachVisibility visibility = AttachVisibility::SHOWN;
	bool is_initial_database = false;
	bool is_closed = false;
	mutex close_lock;
	unordered_map<string, Value> attach_options;

private:
	//! Clean any (shared) resources held by the database.
	void Cleanup();
};