Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
victorguarana committed May 21, 2024
1 parent e4d6e1a commit 27c4342
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
7 changes: 7 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- [ ] Implement History
- [ ] gomongo.Options
- [ ] Implement Validation Hooks
- [ ] Implement Cache
- [ ] Add Benchmarks
- [ ] Add Badges to README
- [ ] Add Index instructions
66 changes: 66 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package main

import (
"context"
"fmt"
"time"

"github.com/victorguarana/gomongo/gomongo"

Check failure on line 8 in main.go

View workflow job for this annotation

GitHub Actions / Tests (4.4)

no required module provides package github.com/victorguarana/gomongo/gomongo; to add it:

Check failure on line 8 in main.go

View workflow job for this annotation

GitHub Actions / Tests (5)

no required module provides package github.com/victorguarana/gomongo/gomongo; to add it:

Check failure on line 8 in main.go

View workflow job for this annotation

GitHub Actions / Tests (6)

no required module provides package github.com/victorguarana/gomongo/gomongo; to add it:
)

type Movie struct {
ID gomongo.ID `bson:"_id"`
Name string
Year int
}

func main() {
// Setting up the connection to the database
connectionSettings := gomongo.ConnectionSettings{
URI: "mongodb://localhost:27017",
DatabaseName: "mydatabase",
ConnectionTimeout: 60 * time.Second,
}
database, err := gomongo.NewDatabase(context.Background(), connectionSettings)
if err != nil {
panic(err)
}

// Creating a collection
moviesCollection, err := gomongo.NewCollection[Movie](database, "mymovies")
if err != nil {
panic(err)
}

// Inserting a movie
starWarsIV := Movie{
Name: "Star Wars",
Year: 1977,
}
starWarsIV.ID, err = moviesCollection.Create(context.Background(), starWarsIV)
if err != nil {
panic(err)
}

// Updating a movie
starWarsIV.Name = "Star Wars: Episode IV - A New Hope"
err = moviesCollection.UpdateID(context.Background(), starWarsIV.ID, starWarsIV)
if err != nil {
panic(err)
}

// Listing all movies
allMovies, err := moviesCollection.All(context.Background())
if err != nil {
panic(err)
}

fmt.Println("All movies from Mongo: ", allMovies)

// Deleting a movie
err = moviesCollection.DeleteID(context.Background(), starWarsIV.ID)
if err != nil {
panic(err)
}

}

0 comments on commit 27c4342

Please sign in to comment.