Example Javascript based plugin for SQLEditor
This project demonstrates how to write a simple export plugin for SQLEditor using Javascript.
This code is similar to the the bundled HTML Report plugin that ships with SQLEditor, except that it doesn't have a binary component and the plugin type is export rather than report.
The binary component in the plugin bundled with SQLEditor is to work around an obscure code signing issue and doesn't actually do anything.
Plugins are currently either export type or report type.
- Export plugins offer new document dialects for the source sidebar and the Export To File panel. You add a section to the exportTypes dictionary in the Info.plist file.
- Report plugins appear in the Save Report panel. You add a section to the reportTypes dictionary in the Info.plist file.
The pure JS plugin consists of a bundle, an Info.plist file and some javascript.
The Info.plist file specifies the main javascript file (under the scriptFile key) for the plugin. You can also evaluate other javscript files.
For diff support you must add the supportsDiff = YES key value to the SQLEditorPlugin InfoPlist section. This example includes that.
You then need to implement the method exportContainerDiff in your javascript plugin
You get two json containers, the first is the current document, the second is the comparison document.
Currently you need to calculate which objects have been added and which removed by diffing these containers.
The code to do this is in the diff-function.js file
I'm hoping to refactor it a bit. :-)
Current version: No building required, just download and install
- SQLEditor plugins should be located in the directory:
~/Library/Application Support/SQLEditor/Plugins/
- Change the document dialect to the name of the plugin In this example code, the plugin is currently "SQLite (JS)"
Once you have installed the plugin, you can actually edit the plugin while SQLEditor is open.
You will need to hit the manual refresh button above the source view
-
No database support
-
No import support
-
Dialect specific type lists are on the way, but require SQLEditor 3.0.2 or later (not yet released)
There is a SQLEditorJS object which offers some special functions:
SQLEditorJS.evaluate(filename)
This method loads and then evaluates the specified Javascript file, it should be located in the Resources directory of the plugin
SQLEditor.contentsOfFile(filename)
This method loads and returns the contents of the specified file, it should be located in the Resources directory of the plugin
Please send suggestions, feedback or bug reports to support@malcolmhardie.com
Suggestions on more ideomatic javascript or any other technical improvements are extremely welcome.
(See also the git history)
2016-05-19
- Added diff
- Rearranged to be a valid plugin without requiring xcode
2016-05-24
- The example now diffs fields
- Better handling of foreign keys and primary keys
2016-06-02
- Added smarter quoting for object names
- Added index export
- Refactored diff calculation