Custom Drivers
A custom driver is a set of functions that implement our driver.IDriver interface and allow you to bridge between your resources and a source of data.
You could, for example, create an Iridium resource that reads and writes to:
- An API
- A Queue
- A File
Or an optimize driver tailored directly for one data source.
Writing a custom driver
You'll need to develop your own custom driver, then register it with Iridium before using it.
The best way to get started is by first taking a look at the source code for our array driver and gorm driver
You'll need to create a type or struct that implements the following functions
type IDriver[T core.Model] interface {
GetName() string
// Query operations
ListQuery(columns []IDriverColumn[T], filters []IDriverFilter[T], ctx *ctxDriver.ColumnContext) (*ListQueryResult[T], error)
FindByID(id string, relations ...string) (*T, error)
// CRUD operations
Create(v *T) (*T, error)
Update(new *T) (*T, error)
Upsert(new *T) (*T, error)
Delete(v *T) error
BulkDelete(vs []T) error
// Query capabilities
SupportsFiltering() bool
SupportsSearching() bool
SupportsSorting() bool
}Development
For V1 of Iridium we're going a little light on documentation here. Drivers are isolated parts of Iridium meaning you do not need to understand a lot about how iridium works internally to write one.
We'll make a more involved guide in the future, but you should be able to fork our existing drivers to get an impression for how to write one.
Want to create your own guide and contribute it to the project? We'd love that
Register your driver
After creating a custom driver, you'll need to register it with iridium
func init() {
driver.RegisterDriver(
"array", func(config map[string]interface{}) (interface{}, error) {
return func(data interface{}) interface{} {
return NewArrayDriver(data.([]interface{}))
}, nil
},
)
}Sharing your custom driver
Did you create a useful driver? If you feel so inclined, please share it with the community. You can create a plugin and we'll list it publicly on our website!