schema

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PostSchema = schema.Schema{
	Name:      "Post",
	TableName: "posts",
	Fields: []schema.Field{
		{
			Name: "ID",
			Type: schema.UUID,
			Options: schema.FieldOptions{
				PrimaryKey: true,
				Immutable:  true,
			},
		},
		{
			Name: "UserID",
			Type: schema.UUID,
			Options: schema.FieldOptions{
				Validators: []schema.Validator{
					{
						Validate: validator.Required,
					},
				},
			},
		},
		{
			Name: "Title",
			Type: schema.String,
			Options: schema.FieldOptions{
				Validators: []schema.Validator{
					{
						Validate: validator.Required,
					},
				},
			},
		},
		{
			Name: "Body",
			Type: schema.String,
			Options: schema.FieldOptions{
				Validators: []schema.Validator{
					{
						Validate: validator.Required,
					},
				},
			},
		},
		{
			Name:    "Status",
			Type:    schema.String,
			Options: schema.FieldOptions{},
		},
		{
			Name: "CreatedAt",
			Type: schema.Time,
			Options: schema.FieldOptions{
				Immutable: true,
			},
		},
		{
			Name: "UpdatedAt",
			Type: schema.Time,
			Options: schema.FieldOptions{
				Immutable: true,
			},
		},
	},
}
View Source
var UserSchema = schema.Schema{
	Name:      "User",
	TableName: "users",
	Fields: []schema.Field{
		{
			Name: "ID",
			Type: schema.UUID,
			Options: schema.FieldOptions{
				PrimaryKey: true,
				Immutable:  true,
			},
		},
		{
			Name: "Username",
			Type: schema.String,
			Options: schema.FieldOptions{
				Validators: []schema.Validator{
					{
						Validate: validator.Required,
					},
					{
						Fields: []string{"Email"},
						Validate: func(key string) validator.ValidatorFunc {
							return func(v ...any) errors.ValidationError {
								username := v[0].(string)
								email := strings.Split(v[1].(string), "@")[0]
								if strings.Contains(username, email) {
									return errors.NewValidationError(key, "Username should not contain email")
								}

								return nil
							}
						},
					},
				},
			},
		},
		{
			Name:    "Bio",
			Type:    schema.Ref(schema.String),
			Options: schema.FieldOptions{},
		},
		{
			Name: "Email",
			Type: schema.String,
			Options: schema.FieldOptions{
				Validators: []schema.Validator{
					{
						Validate: validator.Required,
					},
					{
						Validate: validator.Email,
					},
				},
			},
		},
		{
			Name: "CreatedAt",
			Type: schema.Time,
			Options: schema.FieldOptions{
				Immutable: true,
			},
		},
		{
			Name: "UpdatedAt",
			Type: schema.Time,
			Options: schema.FieldOptions{
				Immutable: true,
			},
		},
	},
}

Functions

func Run

func Run(dir string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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