GnoSQL Client is a Go library that provides a client for interacting with the GnoSQL in-memory database. It simplifies the process of managing connections, executing queries, and working with data in a GnoSQL database.
- Connection Management: Easily connect to a Gnosql in-memory database.
- Query Execution: Execute queries and retrieve results.
- Data Manipulation: Perform CRUD operations on your Gnosql database.
- Documentation: Well-documented code and usage examples.
go get -u github.com/nanda03dev/gnosql_client
First, connect to the GnoSQL database using the GRPC URI and the desired database name.
var DatabaseName = "test-g-c"
// Connect to the GnoSQL database
db := Connect(GRPC_URI, DatabaseName, true)
Define the collection and its index keys, and create it in the database.
var userCollectionName = "users"
// Define the collection input with index keys
UserCollectionInput := CollectionInput{
CollectionName: userCollectionName,
IndexKeys: []string{"city", "pincode"},
}
// Create the collection
db.CreateCollections([]CollectionInput{UserCollectionInput})
Get the collection, and then perform Create, Read, Update, and Delete operations on documents within the collection.
// Get the collection
var userCollection *Collection = db.Collections[userCollectionName]
// Create a document
user1 := make(Document)
user1["name"] = "Nandakumar"
user1["city"] = "Chennai"
user1["pincode"] = "600100"
// Insert the document into the collection
userCollection.Create(user1)
// Read the document by its ID
var docId = "your-document-id" // Replace with your actual document ID
userCollection.Read(docId)
// Update the document
user1["designation"] = "developer"
userCollection.Update(docId, user1)
// Define a filter to find documents by a specific field
var filter MapInterface = MapInterface{
"name": "Nandakumar",
}
// Filter documents in the collection
userCollection.Filter(filter)
// Delete the document by its ID
userCollection.Delete(docId)
Delete a specific collection from the database.
// Define the collection to be deleted
var collectionDeleteInput = CollectionDeleteInput{
Collections: []string{userCollectionName},
}
// Delete the collection
db.DeleteCollections(collectionDeleteInput)