GithubHelp home page GithubHelp logo

pocketpase-gen's Introduction

pocketpase-gen

This is a poc for code gen of models of pocketpase instance.

How to use

Install the binary with go install github.com/pocketbase/pocketpase-gen/cmd/pb-gen@latest

pb-gen models --help
Generate models from a pocketbase instance sqlite file

Usage:
  pb-gen models [flags]

Flags:
  -h, --help                    help for models
      --package-folder string   path to package folder (default "modelspb")
      --package-name string     name of the package (default "modelspb")

Global Flags:
      --db-path string   path to pocketbase instance sqlite file (default "pb_data/data.db")
      --verbose          enable verbose mode

Runnin pb-gen models will create a folder modelspb with all the models of the pocketbase instance. By default the db-path is pb_data/data.db.

Currently supported things

  • Getter
  • Setter

What can be imagined

  • Better documentation for each fields (validations description, if required ...)
  • Better documentation for model (rules ...)
  • Expand relations generation
  • Enums generations for select fields (field name as suffix ?)
  • Hook models generation (beforeSave, afterSave, beforeDelete, afterDelete but with the model as parameter)
  • Add/Remove for arrayable fields
  • Add automated tests
  • id, created, updated gen on models

pocketpase-gen's People

Contributors

alexisvisco avatar

Stargazers

 avatar  avatar Clayton Kehoe avatar Pavel Rusakov avatar  avatar Preslav Rachev avatar

Watchers

 avatar

Forkers

gedw99

pocketpase-gen's Issues

Add db model to code gen

How about if we extend the template to Add DB Model.

For example :

package models

import "github.com/pocketbase/pocketbase/models"

var _ models.Model = (*Task)(nil)

type Task struct {
	models.BaseModel
	Title       string `db:"title" json:"title"`
	Description string `db:"description" json:"description"`
	Board       string `db:"board" json:"board"`
	Owner       string `db:"owner" json:"owner"`
	Completed   bool   `db:"completed" json:"completed"`
}

func (t *Task) TableName() string {
	return "tasks"
}

currently we only get Getters and setters:

// Code generated by pb-codegen v0.1 DO NOT EDIT.
package modelspb

import (
    "github.com/pocketbase/pocketbase/models"
)

// Tasks is a wrapper around models.Record for type safe operations on the collection tasks.
type Tasks struct {
    Record *models.Record
}

// GetTitle returns the value of the "title" field
func (m *Tasks) GetTitle() string {
    return m.Record.GetString("title")
}

// SetTitle sets the value of the "title" field
func (m *Tasks) SetTitle(val string)  {
    m.Record.Set("title", val)
}

// GetDescription returns the value of the "description" field
func (m *Tasks) GetDescription() string {
    return m.Record.GetString("description")
}

// SetDescription sets the value of the "description" field
func (m *Tasks) SetDescription(val string)  {
    m.Record.Set("description", val)
}

// GetBoard returns the value of the "board" field
// Relation collection related : d5tpeg8jtjkexq1
func (m *Tasks) GetBoard() string {
    return m.Record.GetString("board")
}

// SetBoard sets the value of the "board" field
// Relation collection related : d5tpeg8jtjkexq1
func (m *Tasks) SetBoard(val string)  {
    m.Record.Set("board", val)
}

// GetOwner returns the value of the "owner" field
// Relation collection related : _pb_users_auth_
func (m *Tasks) GetOwner() string {
    return m.Record.GetString("owner")
}

// SetOwner sets the value of the "owner" field
// Relation collection related : _pb_users_auth_
func (m *Tasks) SetOwner(val string)  {
    m.Record.Set("owner", val)
}

// GetCompleted returns the value of the "completed" field
func (m *Tasks) GetCompleted() bool {
    return m.Record.GetBool("completed")
}

// SetCompleted sets the value of the "completed" field
func (m *Tasks) SetCompleted(val bool)  {
    m.Record.Set("completed", val)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.