sqlcgeneratecrud

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: MIT Imports: 1 Imported by: 0

README

sqlc generate crud

is a library that generates CRUD in sql operations for a struct using.

Case of use

was created in order to decrease the time spent writing queries using the sqlc: A SQL Compiler. sqlc

Installation

go get github.com/Paulo-Lopes-Estevao/sqlc-generate-crud

Usage

Required create a file sqlc.yaml
version: "2"
sql:
  - schema: "postgresql/schema.sql"
    queries: "postgresql"
    engine: "postgresql"
    gen:
      go:
        package: "authors"
        out: "postgresql"

generated sql files will be saved in the queries path folder in the sqlc.yaml file

function Generate has 2 parameters:

  • data : struct that will be used to generate the CRUD operations
  • options : struct that will be used to configure the generation tag and pathTarget
// GenerateConfig is a struct that will be used to configure the generation
type GenerateConfig struct {
    Tag        string
    PathTarget string
}
Example
package main

import (
    "github.com/Paulo-Lopes-Estevao/sqlc-generate-crud"
)

type User struct {
    ID int64 `json:"id"`
    Name string `json:"name"`
    Email string `json:"email"`
}

func main() {
	err := sqlcgeneratecrud.Generate(User{}, &sqlcgeneratecrud.GenerateConfig{})
	if err != nil {
        panic(err)
    }
}

Contributing

Before opening an issue or pull request, please check the project's contribution documents.

Please read CONTRIBUTING.md for details about our code of conduct, and the process for submitting pull requests.

Support Donate

If you find this project useful, you can buy author a glass of juice 🧃

ko-fi

also a coffee ☕️

Buy Me A Coffee

will be very grateful to you for your support 😊.

Documentation

Overview

Package sqlcgeneratecrud provides a set of utilities for generating CRUD SQL statements such as INSERT, SELECT, UPDATE and DELETE.

Source code and other details for the project are available at GitHub:

https://github.com/Paulo-Lopes-Estevao/sqlc-generate-crud

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(data interface{}, option *GenerateConfig) error

Generate generates CRUD SQL statements for the given data using the specified options. It returns an error if any error occurs during the generation process.

Types

type GenerateConfig

type GenerateConfig struct {
	TagFormat  string // The tag format to use for struct field tags (default: "json").
	PathTarget int    // The target path for the generated SQL files (default: 0).
}

GenerateConfig represents the configuration options for generating CRUD SQL statements.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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