Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reset function to db backend #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Qualenritter
Copy link
Contributor

the reset function counts all entries in all tables, and then deletes every table within the specified namespace.
this is for unit tests which require a clean backend.
after the test this function can be used to verify, that there are only empty schemata

@michaelkuhn michaelkuhn self-assigned this Sep 16, 2019
#define sql_autoincrement_string ""
#define sql_autoincrement_string " "
#define sql_last_insert_id_string " SELECT last_insert_rowid() "
#define sql_get_table_names "SELECT name FROM sqlite_master WHERE type='table' AND name LIKE '%s_%%'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has conflicts, please fix them.

@@ -108,10 +108,29 @@ gboolean j_backend_operation_unwrap_db_update (JBackend*, gpointer, JBackendOper
gboolean j_backend_operation_unwrap_db_delete (JBackend*, gpointer, JBackendOperation*);
gboolean j_backend_operation_unwrap_db_query (JBackend*, gpointer, JBackendOperation*);

gboolean j_backend_operation_unwrap_reset(JBackend* backend,gpointer,JBackendOperation*);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be j_backend_operation_unwrap_db_reset?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intention was to have one reset function for all backend types

gboolean j_backend_operation_to_message (JMessage* message, JBackendOperationParam* data, guint len);
gboolean j_backend_operation_from_message (JMessage* message, JBackendOperationParam* data, guint len);
gboolean j_backend_operation_from_message_static (JMessage* message, JBackendOperationParam* data, guint len);

static const JBackendOperation j_backend_operation_reset = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about naming. The structs should also be in the same order as the functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intention was to have one reset function for all backend types

@@ -429,6 +436,7 @@ gboolean j_backend_db_delete (JBackend*, gpointer, gchar const*, bson_t const*,
gboolean j_backend_db_query (JBackend*, gpointer, gchar const*, bson_t const*, gpointer*, GError**);
gboolean j_backend_db_iterate (JBackend*, gpointer, bson_t*, GError**);

gboolean j_backend_reset (JBackend* backend, gpointer, GError**);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above for naming.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intention was to have one reset function for all backend types

/**
* delete everything in the backend
* \param[in] which namespace to delete
* \param[out] how many "things" are deleted within the specified namespace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no in and out parameters in the actual function below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gpointer is an input parameter containing a batch structure, Error is a out parameter, where the error message-string may contain the number of elements which are deleted

@@ -53,7 +53,8 @@ enum JMessageType
J_MESSAGE_DB_INSERT,
J_MESSAGE_DB_UPDATE,
J_MESSAGE_DB_DELETE,
J_MESSAGE_DB_QUERY
J_MESSAGE_DB_QUERY,
J_MESSAGE_RESET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J_MESSAGE_DB_RESET?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intention was to have one reset function for all backend types - that is why there is no DB prefix

* \param[in] which namespace to delete
* \param[out] how many "things" are deleted within the specified namespace
*/
gboolean (*backend_reset)(gpointer, GError**);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not inside one of the unions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intention was to have one reset function for all backend types

@@ -113,6 +113,8 @@ gboolean j_db_internal_delete (gchar const* namespace, gchar const* name, bson_t
gboolean j_db_internal_query (gchar const* namespace, gchar const* name, bson_t const* selector, gpointer* iterator, JBatch* batch, GError** error);
gboolean j_db_internal_iterate (gpointer iterator, bson_t* metadata, GError** error);

gboolean j_internal_reset (gchar const* namespace, JBatch* batch, GError** error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j_db_internal_reset?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intention was to have one reset function for all backend types - maybe this should be moved somewhere in the core if it should be available for all backend types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants