Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Simple and async java-library for mysql and mongodb database-connections

License

NotificationsYou must be signed in to change notification settings

Heliumdioxid/database-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub release (latest by date including pre-releases)GitHubGitHub issuesGitHub pull requests

a simple andasync java-library for mysql and mongodbdatabase-connections

It is an easy-to-use library that (until now) can connect to mysql and mongodb databases.
In addition, interactions with databases are simplified.Feel free to leave a ⭐ if you appreciate the work.

getting startedreport a bugfeature request


Table of Contents


🧪 Installation

You can integrate the database-api into your project with Maven or Gradle.

Maven

Maven repository:

<repositories>    <repository>        <id>jitpack.io</id>        <url>https://jitpack.io</url>    </repository></repositories>

Maven dependencies:

<dependency>    <groupId>com.github.Heliumdioxid.database-api</groupId>    <artifactId>api</artifactId>    <version>1.0.0-rc1</version></dependency><dependency>    <groupId>com.github.Heliumdioxid.database-api</groupId>    <artifactId>mysql</artifactId>    <version>1.0.0-rc1</version></dependency><dependency>    <groupId>com.github.Heliumdioxid.database-api</groupId>    <artifactId>mongo</artifactId>    <version>1.0.0-rc1</version></dependency>

Gradle

Gradle repository:

maven {    name'jitpack.io'    url'https://jitpack.io'}

Gradle dependency:

dependencies {    implementation'com.github.Heliumdioxid.database-api:api:1.0.0-rc1'}dependencies {    implementation'com.github.Heliumdioxid.database-api:mysql:1.0.0-rc1'}dependencies {    implementation'com.github.Heliumdioxid.database-api:mongo:1.0.0-rc1'}

📖 Code examples

First, you have to create aConnectionData, either for a mongo or mysql connection.You need to provide a host, username, password, database-name and port (mostly 3306 for mysql and 27017 for mongodb)

ConnectionDataconnectionData =newConnectionData("127.0.0.1","username","password","database",3306);

mysql-database-connection

🤖 The connection to mysql-databases should work properly.If there are any errors, it would be a great help to report them.

Moreover, you have to create some properties, which are then passed on during the connection:

MySQLConnectionConfigmySQLConnectionConfig =newMySQLConnectionConfig(connectionData);mySQLConnectionConfig.applyDefaultHikariConfig()// recommended setting for HikariCP

After that, the connection to the database can be established like this:

MySQLDatabaseConnectionmySQLDatabaseConnection =newMySQLDatabaseConnection(mySQLConnectionConfig);MySQLConnectionHandlermySQLConnectionHandler;// connect and check for a present value in the optional:mySQLConnectionHandler =mySQLDatabaseConnection.connect().join().get();// get the MySQLConnectionHandler with this method:mySQLConnectionHandler =mySQLDatabaseConnection.getConnectionHandler().get();

TheMySQLConnectionHandler can now be used for communicating with the connected mysql-database:

UpdateResultupdateResult =mySQLConnectionHandler.executeUpdate("query");// execute an update// executes a query and applies the result to a functional interfacebooleanincluded =mySQLConnectionHandler.executeQuery(resultSet ->resultSet.next(),false,"query");

The connection can finally be closed by calling this method:

mySQLDatabaseConnection.disconnect();

mongo-database-connection

🤖 The connection to mongo-databases was not testet yet.If you have tried it, I would be very grateful if you would contact me.

Moreover, you have to create some properties, which are then passed on during the connection:

MongoConnectionConfigmongoConnectionConfig =newMongoConnectionConfig(connectionData);mongoConnectionConfig.applyDefaultMongoClientSettings();// applies default properties like the uri

After that, the connection to the database can be established like this:

MongoDatabaseConnectionmongoDatabaseConnection =newMongoDatabaseConnection(mongoConnectionConfig);MongoConnectionHandlermongoConnectionHandler;// connect and check for a present value in the optional:mongoConnectionHandler =mongoDatabaseConnection.connect().join().get();// get the MongoConnectionHandler with this method:mongoConnectionHandler =mongoDatabaseConnection.getConnectionHandler().get();

TheMongoConnectionHandler can now be used for communicating with the connected mongo-database (few examples):

Optional<MongoCollection<Document>>mongoCollection =mongoConnectionHandler.getCollection("collection").join();Optional<Document>document =mongoConnectionHandler.getDocument("collection","fieldName","value").join();

The connection can finally be closed by calling this method:

mongoDatabaseConnection.disconnect();

⌛ Pending tasks

🤖 Please suggest features that we should include in the api.ReadContributing for details.


🗺️ Contributing

Before submitting issues and pull requests please read theCONTRIBUTING.md file.Please follow these guidelines to make life easier for all of us.


📜 License

database-api is distributed under the terms of theMIT License. A complete version of the license is available in theLICENSE.md in this repository. Any contribution made to this project will be licensed under theMIT License.
All files are Copyright © 2023 Florian H. and all contributors.


☎️ Contact

You can contact me via Discord: Heliumdioxid#3963

About

Simple and async java-library for mysql and mongodb database-connections

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages


[8]ページ先頭

©2009-2025 Movatter.jp