Publish a Package
Let's create your first Trusted Language Extension for database.dev.
Create your package
Create a folder which will contain the extension:
1 2 |
|
Next create a hello_world--0.0.1.sql
file, which will contain your extension's SQL objects. Add the following function definition to this file:
1 2 3 4 5 6 |
|
Let's also add some docs about this extension. Create a README.md
file and add the following content to it:
1 |
|
Lastly, add a hello_world.control
file with the following key-value pairs:
1 2 3 |
|
Your extension is ready to publish. Its name is hello_world
and version is 0.0.1
. For details about what constitutes a valid extension, read about the Structure of an Extension.
Login to database.dev
Before you can publish your extension, you need to authenticate with database.dev. If you don't have an account, sign-up for one on the website. Then follow the steps below:
- Make sure you are logged into the
database.dev
website. - Navigate to the Access Tokens page from the account drop-down at top right.
- Click New Token.
- Enter a token name and click Create Token.
- Copy the generated token. Note that this is the only time the token will be shown.
- On the terminal, run the
dbdev login
command. - Paste the token you copied.
Publish your extension
Now run the dbdev publish
command to publish it.
1 |
|
Your extension is now published to database.dev
and visible under your account profile. You can visit your account profile from the account drop-down at the top right. Users can now install your extension using the dbdev in-database client.
Tips
Here are a few useful tips for creating extensions.
Don't hardcode schemas
It's common to hardcode public
into your SQL files, but this isn't a great practice. Remove all hard-coded schema references so that the user can choose to install the extension in other schemas.
Relocatable schemas
You can define a schema to be relocatable
in the .control
file:
1 2 3 |
|
If this is true
, users can choose where to install their schema:
1 2 3 |
|
If you need to reference the schema in your SQL files, you can use the @extschema@
parameter:
1 2 3 4 5 6 7 8 |
|