Authoring plugins

To use plugins, you must be using Version 2 of the configuration file. The top-level plugins array defines the available plugins.

WASM plugins

WASM plugins are fully sandboxed. Plugins do not have access to the network, filesystem, or environment variables.

In the codegen section, the out field dictates what directory will contain the new files. The plugin key must reference a plugin defined in the top-level plugins map. The options are serialized to a string and passed on to the plugin itself.

{
  "version": "2",
  "plugins": [
    {
      "name": "greeter",
      "wasm": {
        "url": "https://github.com/kyleconroy/sqlc-gen-greeter/releases/download/v0.1.0/sqlc-gen-greeter.wasm",
        "sha256": "afc486dac2068d741d7a4110146559d12a013fd0286f42a2fc7dcd802424ad07"
      }
    }
  ],
  "sql": [
    {
      "schema": "schema.sql",
      "queries": "query.sql",
      "engine": "postgresql",
      "codegen": [
        {
          "out": "gen",
          "plugin": "greeter"
        }
      ]
    }
  ]
}

For a complete working example see the following files:

Process plugins

Process-based plugins offer minimal security. Only use plugins that you trust. Better yet, only use plugins that you’ve written yourself.

In the codegen section, the out field dictates what directory will contain the new files. The plugin key must reference a plugin defined in the top-level plugins map. The options are serialized to a string and passed on to the plugin itself.

{
  "version": "2",
  "plugins": [
    {
      "name": "jsonb",
      "process": {
        "cmd": "sqlc-gen-json"
      }
    }
  ],
   "sql": [
    {
      "schema": "schema.sql",
      "queries": "query.sql",
      "engine": "postgresql",
      "codegen": [
        {
          "out": "gen",
          "plugin": "jsonb",
          "options": {
            "indent": "  ",
            "filename": "codegen.json"
          }
        }
      ]
    }
  ]
}

For a complete working example see the following files: