Platformatic v0.8.0 - autoload, composite keys, schemas, and many more

Platformatic v0.8.0 - autoload, composite keys, schemas, and many more

Hi Folks,

As you likely noticed, we are trying to keep a pace of one release per week on platformatic.

The full release notes are available at: github.com/platformatic/platformatic/releas...

Here are the highlights of the release!

@fastify/autoload support

@fastify/autoload provides a convenient utility to load all Fastify plugins in a folder, automatically applying folder-based routing to all routes defined there.

This enables us to write the following configuration in platformatic.service.yml and platformatic.db.yml:

server:
  hostname: 0.0.0.0
  port: 3042
plugin:
  - './plugins'
  - './routes'

This enables us to automatically load files in directory structured like the following:

├── routes
│   ├── foo
│   │   ├── something.js
│   │   └── bar // all routes defined in this folder will have prefix /foo/bar
│   │       └── baz.js
│   ├── single-plugin
│   │   └── utils.js
│   └── another-plugin.js
└── platformatic.service.json

Many-To-Many relationships

Many-to-Many relationship lets you relate each row in one table to many rows in another table and vice versa.

Many-to-many relationships are implemented in SQL via a "join table", a table whose primary key is composed by the identifier of the two parts of the many-to-many relationship.

Platformatic DB fully supports many-to-many relationships on all supported databases.

Consider the following schema:

CREATE TABLE pages (
  id INTEGER PRIMARY KEY,
  the_title VARCHAR(42)
);
CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  username VARCHAR(255) NOT NULL
);
CREATE TABLE editors (
  page_id INTEGER NOT NULL,
  user_id INTEGER NOT NULL,
  role VARCHAR(255) NOT NULL,
  CONSTRAINT fk_editor_pages FOREIGN KEY (page_id) REFERENCES pages(id),
  CONSTRAINT fk_editor_users FOREIGN KEY (user_id) REFERENCES users(id),
  PRIMARY KEY (page_id, user_id)
);
query {
  editors(orderBy: { field: role, direction: DESC }) {
    user {
      id
      username
    }
    page {
      id
      theTitle
    }
    role
  }
}

As well as routes:

  • GET /editors/user/1/page/1

  • POST /editors/user/1/page/1

  • PUT /editors/user/1/page/1

  • DELETE /editors/user/1/page/1

As well as the usual routes.

Multiple Schemas

Added by Marco Piraccini in #359 and #373, it enables to use create OpenAPI and GraphQL APIs from multiple database schemas.

  "core": {
    "connectionString": "(...)",
    "schema": [
      "schema1", "schema2"
    ],
    ... 
  },

Schemas must be specified in the configuration. These are then automatically set in the PostgreSQL search path for the connection (see here for more info).

LIKE support

Added by Marcelo Mollaj in #360, this community contribution enables us to write queries like:

query {
  posts(where: { longText: { like: "%o%" } }) {
    id
    title
    longText
    counter
  }
}