-
Notifications
You must be signed in to change notification settings - Fork 0
Databases
In this application there are two types of databases.
First is a SQLite database used for logging and saving application information. This database will store connection information, user preferences, settings, ect.
The second type of databases are those that the user registers to be able to interact with. These connections will persist for as long as the user would like. Once the application closes they will all disconnect before the application is terminated. The goal with this application is to allow for multiple simultaneous connections. Another goal is to allow connections to different types of databases at the same time, e.g. MongoDB and Microsoft SQL Server. To better manage memory, it may be the case in the future to only allow a certain number of active connections at once.
In order to track these connections, the app stores the connection in a hash map within the App struct. The hash map uses the following type.
var databaseHash map[string]DatabaseThe key to the hashMap will be a combination of the host server, and database name. i.e.
fmt.Sprintf("%s:%s", hostServer, database)Database is an interface defined in dbConnection. Any database connection type should implement this interface, or it will not be able to be stored in the hash map.
For this project, do not embed the interface within the struct that should fulfil it. Let the compiler ensure that the structs are correct. See Code Standards.
The result of queries should be returned within the QueryResult struct. It takes another struct to define the shape of the data returned.
var queryData []UserPermissionResult;
queryData = QueryFunction()
output := QueryResult[UserPermissionResult]{Data: queryData}This struct is used to hold not only the data returned from the database, but also the duration it took for the operation to complete.
This gives insight to both us as the developers as well as the users.
If the query fails, QueryResult should still be returned with duration showing how long it took to fail.
In the case of a fail, Data should be nil.
All query return types should be included as a constraint within the DataResult interface. This ensures that we intend for a struct to be used as a return type. If the struct is not included within DataResult, then the compiler will throw an error.