fastschema

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 27 Imported by: 7

README

Introduction

FastSchema is an open-source headless Content Management System (CMS) designed to simplify the creation and management of structured content. By leveraging schema definitions, FastSchema automates the generation of databases and provides CRUD (Create, Read, Update, Delete) APIs effortlessly.

Note: FastSchema is currently in beta and under active development. We welcome feedback, contributions, and suggestions from the community to help improve the platform and make it more robust and feature-rich.

Overview

At the core of FastSchema lies its schema definition, a blueprint that outlines the structure of your content. This schema acts as the foundation upon which FastSchema builds your database tables and API endpoints, streamlining the development process and allowing you to focus on creating rich, dynamic content.

FastSchema Overview

Features

Fastschema offers a comprehensive suite of features designed to streamline and simplify the process of building and managing dynamic web applications. Whether you're a developer, designer, or content creator, our platform provides the tools you need to create, deploy, and maintain powerful web experiences with ease.

  • Automated Database Generation.
  • RESTful API Generation.
  • Dynamic Content Modeling.
  • Built-in File Management.
  • Built-in Admin Control Panel.
  • Database Support: MySQL, PostgreSQL, SQLite.
  • Role-Based Access Control.

FastSchema simplifies the process of building and managing structured content, providing developers with a powerful toolset to create dynamic, data-driven applications. With its schema-driven approach, automated database generation, and CRUD API creation, FastSchema accelerates development workflows and empowers teams to focus on delivering exceptional digital experiences.

Get started with FastSchema today and revolutionize the way you manage content in your applications!

Documentation

For more information on how to get started with FastSchema, check out our documentation.

Schema Definition

The schema definition is structured JSON that encapsulates the characteristics of your content model. Let's take a closer look at a sample schema definition:

post.json

{
  "name": "post",
  "namespace": "posts",
  "label_field": "name",
  "fields": [
    {
      "type": "string",
      "name": "name",
      "label": "Name",
      "sortable": true
    },
    {
      "type": "relation",
      "name": "category",
      "label": "Category",
      "renderer": {},
      "relation": {
        "schema": "category",
        "field": "posts",
        "type": "o2m"
      },
    }
  ]
}

category.json

{
  "name": "category",
  "namespace": "categories",
  "label_field": "name",
  "fields": [
    {
      "type": "string",
      "name": "name",
      "label": "Name",
      "optional": true,
      "sortable": true
    },
    {
      "type": "text",
      "name": "content",
      "label": "Content",
      "renderer": {
        "class": "editor"
      },
      "optional": true,
      "sortable": true
    },
    {
      "type": "relation",
      "name": "posts",
      "label": "Posts",
      "optional": true,
      "relation": {
        "schema": "post",
        "field": "category",
        "type": "o2m",
        "owner": true,
        "optional": true
      }
    }
  ]
}
Example
Query
GET /api/users/?sort=-age&select=name,email,groups.name&filter={filterObject}
{
  "name": {
    "$like": "test%",
    "$neq": "test2"
  },
  "$or": [
    {
      "email": {
        "$neq": "test",
        "$like": "test%"
      },
      "age": {
        "$lt": 10
      }
    },
    {
      "age": 5
    },
    {
      "$and": [
        {
          "name": {
            "$neq": "test2"
          }
        },
        {
          "age": 5
        }
      ]
    }
  ]
}

Update
PUT /api/users/1
{
  "name": "John Doe",
  "age": 30,
  "room": { "id": 2 },
  "pets": [ { "id": 2 }, { "id": 3 } ],
  "groups": [ { "id": 4 }, { "id": 5 } ],
  "$set": {
    "bio": "Hello World",
    "address": "123 Main St",
    "sub_room": { "id": 2 },
    "sub_pets": [ { "id": 2 }, { "id": 3 } ],
    "sub_groups": [ { "id": 4 }, { "id": 5 } ]
  },
  "$clear": {
    "bio": true,
    "address": true,
    "room": true,
    "sub_pets": true,
    "sub_groups": true,
    "pets": [ { "id": 2 }, { "id": 3 } ],
    "groups": [ { "id": 4 }, { "id": 5 } ]
  },
  "$add": {
    "pets": [ { "id": 2 }, { "id": 3 } ],
    "groups": [ { "id": 4 }, { "id": 5 } ],
    "age": 1,
    "salary": 1000
  },
  "$expr": {
    "bio": "LOWER(`bio`)",
    "address": "CONCAT(`address`, ' ', `city`, ' ', `state`, ' ', `zip`)"
  }
}

Extend

FastSchema is a flexible and extensible application that allows you to customize and extend its functionality to meet your specific requirements. This guide provides an overview of the different ways you can extend FastSchema, including customizing the API, adding new features, and integrating with third-party services.

Using FastSchema as a module
package main

import (
	"github.com/fastschema/fastschema"
	"github.com/fastschema/fastschema/app"
	"github.com/fastschema/fastschema/db"
	"github.com/fastschema/fastschema/schema"
)

func main() {
	newApp, err := fastschema.New(&fastschema.AppConfig{})

	if err != nil {
		panic(err)
	}

	newApp.AddResource(
		app.NewResource("home", func(c app.Context, _ *any) (any, error) {
			return "Welcome to fastschema", nil
		}, app.Meta{app.GET: ""}),
	)

	newApp.OnAfterDBContentList(
    func(query *db.QueryOptions, entities []*schema.Entity) ([]*schema.Entity, error) {
      if query.Model.Schema().Name != "media" {
        return entities, nil
      }

      for _, entity := range entities {
        entity.Set("custom", true)
      }

      return entities, nil
    },
  )

	newApp.Start()
}

Roadmap

  • Improve documentation and testing.
  • Add auth provider.
  • Plugin system.
  • OpenAPI generator.
  • Real-time updates.
  • GraphQL support.
  • Webhooks.
  • Client SDKs.

Testing

FastSchema comes with a suite of automated tests to ensure the stability and reliability of the platform.

Fastschema come with integration tests that require a database connection. You can use the following command to create DB containers.

cd tests/integration
docker compose up -d

To run the tests, execute the following command:

go test ./...

You can skip the integration tests by running tests for packages only.

./tests/test.sh ./schema

Dependencies

FastSchema is built using the Go programming language and leverages a number of open-source libraries to provide its core functionality. Some of the key dependencies include:

Contributing

We welcome contributions from the community and encourage developers to get involved in the project. Whether you're a seasoned developer or just getting started, there are plenty of ways to contribute to FastSchema.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(config *AppConfig) (_ *App, err error)

func (*App) AddMiddlewares

func (a *App) AddMiddlewares(middlewares ...app.Middleware)

func (*App) AddResource

func (a *App) AddResource(resource *app.Resource)

func (*App) DB

func (a *App) DB() db.Client

func (*App) Disk

func (a *App) Disk(names ...string) app.Disk

func (*App) GetRoleDetail

func (a *App) GetRoleDetail(roleID uint64) *app.Role

func (*App) GetRolePermission

func (a *App) GetRolePermission(roleID uint64, action string) *app.Permission

func (*App) GetRolesFromIDs

func (a *App) GetRolesFromIDs(ids []uint64) []*app.Role

func (*App) Hooks

func (a *App) Hooks() *app.Hooks

func (*App) Key

func (a *App) Key() string

func (*App) Logger

func (a *App) Logger() logger.Logger

func (*App) OnAfterDBContentList

func (a *App) OnAfterDBContentList(hook db.AfterDBContentListHook)

func (*App) OnAfterResolve

func (a *App) OnAfterResolve(middlewares ...app.Middleware)

func (*App) OnBeforeResolve

func (a *App) OnBeforeResolve(middlewares ...app.Middleware)

func (*App) Reload

func (a *App) Reload(migration *db.Migration) (err error)

func (*App) Resources

func (a *App) Resources() *app.ResourcesManager

func (*App) Roles

func (a *App) Roles() []*app.Role

func (*App) SchemaBuilder

func (a *App) SchemaBuilder() *schema.Builder

func (*App) SetupToken

func (a *App) SetupToken() (string, error)

func (*App) Start

func (a *App) Start()

func (*App) UpdateCache

func (a *App) UpdateCache() error

type AppConfig

type AppConfig struct {
	Dir          string
	AppKey       string
	Port         string
	DashURL      string
	APIBaseName  string
	DashBaseName string
	Logger       logger.Logger
	DB           db.Client
	Storage      *app.StorageConfig
}

Directories

Path Synopsis
pkg
services

Jump to

Keyboard shortcuts

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