Supercharge your web backend development with crudiator.
- Define the schema
var (
studentCrudiator = crudiator.MustNewEditor(
"students",
crudiator.POSTGRESQL,
crudiator.NewField("id", crudiator.IsPrimaryKey, crudiator.IncludeOnRead),
crudiator.NewField("name", crudiator.IncludeAlways),
crudiator.NewField("age", crudiator.IncludeAlways),
crudiator.NewField("created_at", crudiator.IncludeOnCreate, crudiator.IncludeOnRead),
crudiator.NewField("updated_at", crudiator.IncludeOnUpdate, crudiator.IncludeOnRead),
crudiator.NewField("school_id", crudiator.IncludeOnCreate, crudiator.IncludeOnRead, crudiator.IsSelectionFilter),
).SoftDelete(true, "deleted_at").
MustPaginate(crudiator.KEYSET, "id").
Build()
)
studentCrudiator
can be used concurrently since it does not store any state data.
- Call the CRUD functions by passing two things:
- a form from which to pull values from
- the
*sql.DB
handle to write and read values from.
studentCrudiator.Create(form, db)
Refer to tests for additional use cases
Pagination is supported when reading data.
The following pagination strategies are implemented:
- Offset pagination - Uses
OFFSET
andLIMIT
which allows skipping to specific offsets. However, as the size of data grows, it becomes significally slow since the entire table needs to be scanned in order to determine the offset. - Keyset pagination - Utilizses an index to prevent full table scan. Implementation at the moment uses the following since most tables will have numeric keys:
WHERE indexedColumn > :lastIndexColumnValue:
ORDER BY indexedColumn ASC
FETCH NEXT 200 ROWS ONLY;
:lastIndexColumnValue:
is the value of the previous value, initially 0, which automatically will return the first 200 rows.
The disadvantage of keyset pagination is that you cannot skip to a specific row offset.
There are two callback functions:
PreActionCallback
PostActionCallback
Each of these is invoked before and after each function of the CRUD is called.
Library | Status | Adapter |
---|---|---|
net/http | YES | nethttp |
go-fiber | NO | gofiber |
gin | NO |
Database | Create | Read | Update | Delete | TESTED |
---|---|---|---|---|---|
PostgreSQL | YES | YES | YES | YES | YES |
MYSQL | YES | YES | YES | YES | NO |
SQLITE | YES | YES | YES | YES | NO |
crudiator does not provide data validation. Validation is not appropriate at this layer. It should be trivial to use data validators at a higher layer before passing data to crudiator.