https://github.com/whynotmax/databaseengine
A simple database engine for Java applications.
https://github.com/whynotmax/databaseengine
Last synced: about 1 year ago
JSON representation
A simple database engine for Java applications.
- Host: GitHub
- URL: https://github.com/whynotmax/databaseengine
- Owner: whynotmax
- Created: 2024-09-08T13:17:14.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-08T14:02:25.000Z (over 1 year ago)
- Last Synced: 2025-02-05T05:38:51.511Z (over 1 year ago)
- Language: Java
- Size: 75.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DatabaseEngine
DatabaseEngine is a Java-based project that provides a simple and flexible way to interact with different types of databases, including JSON and MongoDB.
## Features
- **JSON Database**: Store and retrieve data in JSON format.
- **MongoDB Database**: Store and retrieve data using MongoDB.
- **MySQL Database**: Store and retrieve data using MySQL.
- **SQLite Database**: Store and retrieve data using SQLite.
## Getting Started
### Prerequisites
- Java 21
- Gradle
- MongoDB (for MongoDB database functionality)
- MySQL (for MySQL database functionality)
- Gson (for JSON database functionality)
### Installation
1. Clone the repository:
```sh
git clone https://github.com/whynotmax/DatabaseEngine.git
cd DatabaseEngine
```
2. Build the project using Gradle:
```sh
gradle build
```
### Usage
#### JSON Database
```java
JSONDatabase jsonDatabase = new JSONDatabase<>("data.json", Person.class);
Person person1 = new Person("1", "John Doe");
jsonDatabase.save(person1);
System.out.println("Saved to JSON: " + jsonDatabase.getEntity("1"));
```
#### MongoDB Database
```java
MongoDBDatabase mongoDBDatabase = new MongoDBDatabase<>(DatabaseCredentials.createMongoDatabase(connectionUrl), database, collection, Person.class);
Person person2 = new Person("2", "Jane Doe");
mongoDBDatabase.save(person2);
System.out.println("Saved to MongoDB: " + mongoDBDatabase.getEntity("2"));
mongoDBDatabase.close();
```
#### MySQL Database
```java
MySQLDatabase mySQLDatabase = new MySQLDatabase(DatabaseCredentials.createMySQLDatabase(host, port, database, username, password), tableName, Person.class);
Person person3 = new Person("3", "Alice Smith");
mySQLDatabase.save(person3);
System.out.println("Saved to MySQL: " + mySQLDatabase.getEntity("3"));
mySQLDatabase.close();
```
Please make sure that the tables are created in the MySQL database before running the code. Alternatively, you can use the following code to create the table:
```java
mySQLDatabase.createTable(TableBuilder);
```
#### SQLite Database
```java
SQLiteDatabase sqLiteDatabase = new SQLiteDatabase(DatabaseCredentials.createSQLiteDatabase(database), tableName, Person.class);
Person person4 = new Person("4", "Bob Smith");
sqLiteDatabase.save(person4);
System.out.println("Saved to SQLite: " + sqLiteDatabase.getEntity("4"));
sqLiteDatabase.close();
```
Please make sure that the tables are created in the SQLite database before running the code. Alternatively, you can use the following code to create the table:
```java
sqLiteDatabase.createTable(TableBuilder);
```
## License
Distributed under the MIT License. See `LICENSE` for more information.
## Contact
E-Mail: max@keinesecrets.de