https://github.com/paloaltonetworks/manipulate
Go library to perform CRUD operations on an Elemental model with multiple backend implementations
https://github.com/paloaltonetworks/manipulate
Last synced: 6 months ago
JSON representation
Go library to perform CRUD operations on an Elemental model with multiple backend implementations
- Host: GitHub
- URL: https://github.com/paloaltonetworks/manipulate
- Owner: PaloAltoNetworks
- License: apache-2.0
- Created: 2016-05-21T03:06:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-05-02T21:19:28.000Z (6 months ago)
- Last Synced: 2025-05-02T22:26:16.625Z (6 months ago)
- Language: Go
- Homepage:
- Size: 4.76 MB
- Stars: 14
- Watchers: 18
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Manipulate
[](https://www.codacy.com/gh/PaloAltoNetworks/manipulate/dashboard?utm_source=github.com&utm_medium=referral&utm_content=PaloAltoNetworks/manipulate&utm_campaign=Badge_Grade) [](https://www.codacy.com/gh/PaloAltoNetworks/manipulate/dashboard?utm_source=github.com&utm_medium=referral&utm_content=PaloAltoNetworks/manipulate&utm_campaign=Badge_Coverage)
> Note: this readme is a work in progress
Package manipulate provides everything needed to perform CRUD operations on an
[elemental](https://go.aporeto.io/elemental) based data model.The main interface is `Manipulator`. This interface provides various methods for
creation, modification, retrieval and so on.A Manipulator works with `elemental.Identifiable`.
The storage engine used by a Manipulator is abstracted. By default manipulate
provides implementations for Mongo, ReST HTTP 1and a Memory backed datastore.
You can of course implement Your own storage implementation.There is also a mocking package called maniptest to make it easy to mock any
manipulator implementation for unit testing.Each method of a Manipulator is taking a `manipulate.Context` as argument. The
context is used to pass additional informations like a Filter, or some
Parameters.## Example for creating an object
```go
// Create a User from a generated Elemental model.
user := models.NewUser() // always use the initializer to get various default value correctly set.
user.FullName := "Antoine Mercadal"
user.Login := "primalmotion"// Create Mongo Manipulator.
m := manipmongo.New("127.0.0.1", "test")// Then create the User.
m.Create(nil, user)
```## Example for retreving an object
```go
// Create a Context with a filter.
ctx := manipulate.NewContextWithFilter(elemental.NewFilterComposer().
WithKey("login").Equals("primalmotion").
Done(),
)// Retrieve the users matching the filter.
var users models.UserLists
m.RetrieveMany(ctx, &users)
```