Update Home
parent
be480d2c2d
commit
c2156285af
60
Home.md
60
Home.md
@ -1,7 +1,26 @@
|
|||||||
# Getting Started
|
# Feather
|
||||||
Hello, let's get started with using Feather!
|
Feather is an efficient lightweight database library.
|
||||||
|
|
||||||
|
## Dependency
|
||||||
|
First off, you need to get the dependency into your project so you can use it.
|
||||||
|
|
||||||
|
### Maven
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.braydon</groupId>
|
||||||
|
<artifactId>Feather</artifactId>
|
||||||
|
<version>1.0-dev</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle (Kotlin DSL)
|
||||||
|
```kotlin
|
||||||
|
implementation("me.braydon:Feather:1.0-dev")
|
||||||
|
```
|
||||||
|
|
||||||
## Connecting
|
## Connecting
|
||||||
|
Connecting to a database is very simple, all you have to do is construct the instance of the database you would like to connect to, and then invoke it's `#connect(credentials)` method.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
MongoDB mongo = new MongoDB(); // Create the database instance
|
MongoDB mongo = new MongoDB(); // Create the database instance
|
||||||
mongo.connect(new ConnectionString("mongodb://admin:p4$$w0rd@localhost:27017/feather?authSource=admin")); // Connect to the MongoDB server
|
mongo.connect(new ConnectionString("mongodb://admin:p4$$w0rd@localhost:27017/feather?authSource=admin")); // Connect to the MongoDB server
|
||||||
@ -10,4 +29,39 @@ mongo.connect(new ConnectionString("mongodb://admin:p4$$w0rd@localhost:27017/fea
|
|||||||
mongo.close();
|
mongo.close();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Other Resources
|
## Examples
|
||||||
|
|
||||||
|
### Saving & Finding an entity
|
||||||
|
```java
|
||||||
|
public static void main(@NonNull String[] args) {
|
||||||
|
MongoDB mongo = new MongoDB(); // Create the database instance
|
||||||
|
mongo.connect(new ConnectionString("mongodb://admin:p4$$w0rd@localhost:27017/feather?authSource=admin")); // Connect to the MongoDB server
|
||||||
|
|
||||||
|
// Create a new player repository, and add a player to it
|
||||||
|
MongoRepository<UUID, Player> repository = mongo.newRepository("players", Player.class);
|
||||||
|
repository.save(new Player(uuid, "Rainnny")); // Save our player
|
||||||
|
|
||||||
|
// Get the player from the repository that we just saved
|
||||||
|
Player found = repository.find(uuid);
|
||||||
|
System.out.println("player = " + (found == null ? "n/a" : found));
|
||||||
|
|
||||||
|
// Close the database connection after our app is finished
|
||||||
|
mongo.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple player entity.
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor @AllArgsConstructor @Getter @ToString
|
||||||
|
public static class Player {
|
||||||
|
/**
|
||||||
|
* The uuid of this player.
|
||||||
|
*/
|
||||||
|
@Id @Field private UUID uuid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of this player.
|
||||||
|
*/
|
||||||
|
@Field(key = "name") @Index private String username;
|
||||||
|
}
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user