Make Extension
Besides using the published extensions, you could also customize extensions by using our base extension components.
VulcanSQL provides 17 categories of extension to make you write your customized extension and put the base extension component into @vulcan-sql/core, @vulcan-sql/build, @vulcan-sql/serve separately.
You could customize your extension by extending 17 categories base extension components.
Create your extension package
Create a extension folder and use
npm init
to set package information, e.g:my-extension
.$ mkdir my-extension
$ cd my-extension
my-extension $ npm initSet your package name be
my-first-extensions
inpackage.json
Install VulcanSQL base extension packages.
Because base extension components existed in @vulcan-sql/core, @vulcan-sql/build, @vulcan-sql/serve separately.
You could install these 3 packages all or according to which base extension you need to install its package.
my-extension $ npm i @vulcan-sql/core @vulcan-sql/build @vulcan-sql/serve
Customize extension
Import the base extension class from the extension package under the my-extension
folder.
Here is an sample for extending InputValidator
class to MyValidator
in the my-validator
module file:
- NodeJS with CommonJS
- NodeJS with ES6
- NodeJS with Typescript
const { InputValidator } = require('@vulcan-sql/core');
class MyValidator extends InputValidator {
validateSchema(args) {
// implemented ...
}
validateData(value, args) {
// implemented ...
}
}
module.exports = { MyValidator };
import { InputValidator } from '@vulcan-sql/core';
export class MyValidator extends InputValidator {
validateSchema(args) {
// implemented ...
}
validateData(value, args) {
// implemented ...
}
}
import { InputValidator } from '@vulcan-sql/core';
export class MyValidator extends InputValidator {
public validateSchema(args: any) {
// implemented ...
}
public validateData(value: any, args: any) {
// implemented ...
}
}
Export customized extensions
Create
index
file to be entry:- NodeJS
- Typescript
my-extension $ touch index.js
my-extension $ touch index.ts
Export your customized extensions:
You should export the extensions to make VulcanSQL could detect and load it for use.
- NodeJS with CommonJS
- NodeJS with Typescript
If you use
module.exports
to export your customized extension class.const { MyValidator } = require('./my-validator.js');
module.exports = MyValidator;We also support 2 different way to use
module.exports
when you customized multiple extensions in the package:- use
module.exports
extensions by array type when you customized multiple same type base extensions:
const { MyValidator1 } = require('./my-validator1.js');
const { MyValidator2 } = require('./my-validator2.js');
module.exports = [MyValidator1, MyValidator2];- use
module.exports
extensions by key-value type when you customized multiple different type base extensions:
const { MyValidator1 } = require('./my-validator1.js');
const { MyDataSource1 } = require('./my-data-source1.js');
const { MyDataSource2 } = require('./my-data-source2.js');
module.exports = {
validators: MyValidator1;
dataSources: [ MyDataSource1, MyDataSource2 ];
}If you use
exports
to export your customized extension class, theexports
is amodule.exports
alias, so same as above.const { MyValidator } = require('./my-validator.js');
exports = MyValidator;You could also use
exports
to export multiple same type extensions.const { MyValidator1 } = require('./my-validator1.js');
const { MyValidator2 } = require('./my-validator2.js');
exports = [MyValidator1, MyValidator2];You could also use
exports
to export multiple different type extensions.const { MyValidator1 } = require('./my-validator1.js');
const { MyDataSource1 } = require('./my-data-source1.js');
const { MyDataSource2 } = require('./my-data-source2.js');
exports = {
validators: MyValidator1;
dataSources: [ MyDataSource1, MyDataSource2 ];
}infoUse NodeJS with ES6 is the same as Typescript.
If you use
export
to export your customized extension class.export { MyValidator } from './my-validator.ts';
You could also use
export
to export multiple same type or different type extensions.export { MyValidator1 } from './my-validator1';
export { MyValidator2 } from './my-validator2';But you could also use
export
with key-value type to export multiple different type extensions clearly.import { MyValidator1 } from './my-validator1';
import { MyDataSource1 } from './my-data-source1';
import { MyDataSource2 } from './my-data-source2';
export {
validators: MyValidator1;
dataSources: [ MyDataSource1, MyDataSource2 ];
}If you use
export default
to export your customized extension class.import { MyValidator } from './my-validator';
export default [MyValidator];You could also use
export default
to export multiple same type extensions by array type.import { MyValidator1 } from './my-validator1';
import { MyValidator2 } from './my-validator2';
export default [MyValidator1, MyValidator2];You could also use
export default
to export multiple different type extensions by key-value type.import { MyValidator1 } from './my-validator1';
import { MyDataSource1 } from './my-data-source1';
import { MyDataSource2 } from './my-data-source2';
export default {
validators: MyValidator1;
dataSources: [ MyDataSource1, MyDataSource2 ];
}
Use your customized extensions
You could use npm link to link extension package locally:
my-extension $ npm link
Or you could install local extension package by npm i <extension-package-folder>
:
$ npm i /Users/<user-name>/Code/my-extension
After you installed local extension package, set the extension configuration in vulcan.yaml
, same like our other extensions:
extensions:
my-extension: 'my-first-extensions' # package name
my-extension:
# my extension setting
Then use vulcan start
to run it.