/*
 * Seagull: A SQLite helper library
 * Copyright (C) Seagull Developers
 *
 * Seagull is the legal property of its developers, whose names are too
 * numerous to list here. Please refer to the AUTHORS file distributed with
 * this source distribution
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#if !defined(SEAGULL_GLOBAL_HEADER_INSIDE) && !defined(SEAGULL_COMPILATION)
# error "only <seagull.h> may be included directly"
#endif

#ifndef SEAGULL_DB_H
#define SEAGULL_DB_H

#include <glib.h>
#include <gio/gio.h>

#include "seagulltypes.h"
#include "seagullversion.h"

G_BEGIN_DECLS

#define SEAGULL_DB_ERROR seagull_db_error_quark()

/**
 * SeagullDBError:
 * @SEAGULL_DB_ERROR_NEW_FAILED: opening the database failed
 * @SEAGULL_DB_ERROR_CLOSE_FAILED: closing the database failed
 *
 * Error codes returned when creating and closing databases.
 *
 * Since: 0.2
 */
typedef enum {
	SEAGULL_DB_ERROR_NEW_FAILED SEAGULL_AVAILABLE_ENUMERATOR_IN_0_2,
	SEAGULL_DB_ERROR_CLOSE_FAILED SEAGULL_AVAILABLE_ENUMERATOR_IN_0_2,
} SeagullDBError;

/**
 * seagull_db_error_quark:
 *
 * The error domain to identify errors when opening and closing databases.
 *
 * Returns: The error domain.
 *
 * Since: 0.2
 */
SEAGULL_AVAILABLE_IN_0_2
GQuark seagull_db_error_quark(void);

/**
 * seagull_db_new_in_memory:
 * @error: (out) (nullable): a return address for a #GError
 *
 * Creates a new in memory database.
 *
 * Use [func@db_close] to close the database when done with it.
 *
 * Returns: (transfer full): The new instance.
 *
 * Since: 0.2
 */
SEAGULL_AVAILABLE_IN_0_2
SeagullSqlite3 *seagull_db_new_in_memory(GError **error);

/**
 * seagull_db_new_from_file:
 * @filename: the filename to use
 * @error: (out) (nullable): a return address for a #GError
 *
 * Creates a new database with the given filename.
 *
 * Use [func@db_close] to close the database when done with it.
 *
 * Returns: (transfer full): The new instance.
 *
 * Since: 0.2
 */
SEAGULL_AVAILABLE_IN_0_2
SeagullSqlite3 *seagull_db_new_from_file(const char *filename, GError **error);

/**
 * seagull_db_new_from_uri:
 * @uri: a URI to use
 * @error: (out) (nullable): a return address for a #GError
 *
 * Creates a new database from a URI.
 *
 * Internally this uses `sqlite3_open_v2` with the `SQLITE_OPEN_URI` flag which
 * allows you to fine tune the database setup.
 *
 * Use [func@db_close] to close the database when done with it.
 *
 * Returns: (transfer full): The new instance.
 *
 * Since: 0.2
 */
SEAGULL_AVAILABLE_IN_0_2
SeagullSqlite3 *seagull_db_new_from_uri(const char *uri, GError **error);

/**
 * seagull_db_close:
 * @db: (nullable): the database instance
 * @error: (out) (nullable): a return address for a #GError
 *
 * Closes a database instance.
 *
 * Returns: true on success; otherwise false with @error set.
 *
 * Since: 0.2
 */
SEAGULL_AVAILABLE_IN_0_2
gboolean seagull_db_close(SeagullSqlite3 *db, GError **error);

G_END_DECLS

#endif /* SEAGULL_DB_H */
