crudo

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

README

crudo

A simple CRUD (Create, Read, Update, Delete) library for simple management of data.

Features

  • Based on the repository pattern, it abstracts the data access layer and provides a simple interface for managing data.
  • Criteria (specification) pattern for querying data without bloating the repository implementation.
  • MongoDB and InMemory (unsafe slice) implementation for the repository pattern.

WIP

  • Id value object is opinionated to provide simple operation of the library, it provides creation/updation hooks and get/set for the id. It also has a WIP of compound ids.
  • More tests coverage and examples.

Installation

go get github.com/davfer/crudo

Usage

model.go:

package main

import (
	"github.com/davfer/crudo"
	"github.com/davfer/crudo/entity"
)

type User struct {
	entity.Id
	Slug string
	Name string
	Age  int
}

func (t *User) GetId() entity.Id {
	return t.Id
}

func (t *User) SetId(id entity.Id) error {
	t.Id = id
	return nil
}

func (t *User) GetResourceId() (string, error) {
	return t.Slug, nil
}

func (t User) SetResourceId(s string) error {
	t.Slug = s
	return nil
}

func (t User) PreCreate() error {
	return nil
}

func (t User) PreUpdate() error {
	return nil
}

main.go:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/davfer/crudo"
)

func main() {
	
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

type Repository[K entity.Entity] interface {
	Start(ctx context.Context, onBootstrap func(context.Context) error) error

	Create(context.Context, K) (K, error)
	Read(context.Context, entity.Id) (K, error)
	ReadAll(context.Context) ([]K, error)
	Update(context.Context, K) error
	Delete(context.Context, K) error

	Match(context.Context, criteria.Criteria) ([]K, error)
	MatchOne(context.Context, criteria.Criteria) (K, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL