gobase

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 17 Imported by: 0

README

gobase

automatic schema detection that creates the migrations for your code

gobase-img

Goal

This is the goal for the gobase v0.0.1

Input code:

package main

import (
    "time"
)

type users struct {
    ID        int 
    CreatedAt time.Time 
    UpdatedAt time.Time 
    Name      string
    Email     string
    IsMember  bool
}

Output code:

CREATE TABLE users (
    id INT,
    created_at TIMESTAMP,
    updated_at TIMESTAMP,
    name TEXT,
    email TEXT,
    is_member BOOLEAN
);

Milestones for gobase v0.0.1

  • Parsing the struct
  • SQLite table creation query generator
  • Basic Table Creation
    • Connect to database
    • Create tables
    • Basic error handling
    • Simple CLI command
  • Schema Management
    • Track schema state
    • Detect changes
    • Generate diff
  • Migration System
    • Generate migration files
    • Execute migrations
    • Track migration state
  • Complete CLI
    • All basic commands
    • Configuration handling

Documentation

Index

Constants

View Source
const (
	// Update Types
	NAMEUPDATE     = "Name"
	DATATYPEUPDATE = "DataType"
	// Update Action On
	ONTABLE = "Table"
	ONFIELD = "Field"

	// Creation Types
	FIELD = "Field"
)
View Source
const DBFILENAME = "db.sqlite3"
View Source
const (
	SQLITE = "sqlite3"
)

Variables

View Source
var ErrNoChange = errors.New("No changes detected")

Functions

func CreateMetaTable

func CreateMetaTable(dbCon *sql.DB) error

func DownMigrate

func DownMigrate(dbCon *sql.DB, migrationFile string) error

func GetLatestId

func GetLatestId(dbCon *sql.DB) (int, error)

func MigrationFile

func MigrationFile(
	dbConn *sql.DB,
	fileName, createMigDirName, MigFilename string,
) (newJSON, changeJSON string, err error)

func SqLiteCreateTable

func SqLiteCreateTable(schema Schema) (upQuery, downQuery string)

func SqliteConn

func SqliteConn(dbFileName string) (*sql.DB, error)

func SqliteMigration

func SqliteMigration(changes ChangeLog) (upQuery, downQuery string)

func UpMigrate

func UpMigrate(dbCon *sql.DB, migrationFile, newJSON, changeJSON string) error

Types

type ChangeLog

type ChangeLog struct {
	Creations []Create `json:"creations"`
	Updates   []Update `json:"updates"`
	Deletions []Delete `json:"deletions"`
}

type Create

type Create struct {
	CreationType string `json:"creation_type"`
	ON           string `json:"on"`
	TableName    string `json:"table_name"`
	CreationData string `json:"creation_data"`
}

type Delete

type Delete struct {
	DeletionType string `json:"deletion_type"`
	ON           string `json:"on"`
	TableName    string `json:"table_name"`
	DeletionData string `json:"deletion_data"`
}

type GobaseMetadata

type GobaseMetadata struct {
	ID           int       `gobase:"primary_key"`
	CurrentState string    `gobase:""`
	Changes_made string    `gobase:""`
	CreatedAt    time.Time `gobase:"default:current_timestamp"`
}

This is to be used to create the query when the tags usable is added, currently not supported.

type Schema

type Schema struct {
	SchemaName   string        `json:"schema_name"`
	SchemaFields []SchemaField `json:"schema_fields"`
}

func Parse

func Parse(fileName string) Schema

type SchemaField

type SchemaField struct {
	Name     string `json:"name"`
	DataType string `json:"data_type"`
}

type Update

type Update struct {
	UpdateType string `json:"update_type"`
	ON         string `json:"on"`
	TableName  string `json:"table_name"`
	UpdateData string `json:"update_data"`
}

Directories

Path Synopsis
cmd
gobase command

Jump to

Keyboard shortcuts

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