Skip to content

Commit

Permalink
Merge pull request #1 from binlabs/dev
Browse files Browse the repository at this point in the history
Initial revision
  • Loading branch information
binlabs authored Apr 10, 2022
2 parents e66d9e4 + 7f7ac9d commit 0158162
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# sequel-ace-typescript-bundles
# Sequel Ace Typescript Bundles

A collection of bundles for Sequel Ace meant to aide in development of Typescript projects.

## Installation and Usage

1. Download a ZIP file of the repository and unzip it.
2. Double-click on the bundle package to install it.
3. Launch Sequel Ace and connect to a database. Select a table, then choose a command from the **Bundles** > **Generate** menu.
93 changes: 93 additions & 0 deletions Typescript Interface.saBundle/Support/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<html>
<head>
<title>Typescript Interfaces</title>
<meta charset="UTF-8">
<!-- Some basic styling from Bootstrap and Reboot -->
<style>
*, ::after, ::before {
box-sizing: border-box;
}
body {
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #212529;
text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
.container, .container-fluid, .container-lg, .container-md, .container-sm, .container-xl, .container-xxl {
width: 100%;
padding-right: 0.75rem;
padding-left: 0.75rem;
margin-right: auto;
margin-left: auto;
}
@media (min-width: 576px) {
.container, .container-sm {
max-width: 540px;
}
}
@media (min-width: 768px) {
.container, .container-md, .container-sm {
max-width: 720px;
}
}
@media (min-width: 992px) {
.container, .container-lg, .container-md, .container-sm {
max-width: 960px;
}
}
@media (min-width: 1200px) {
.container, .container-lg, .container-md, .container-sm, .container-xl {
max-width: 1140px;
}
}
@media (min-width: 1400px) {
.container, .container-lg, .container-md, .container-sm, .container-xl, .container-xxl {
max-width: 1320px;
}
}
.alert {
position: relative;
padding: 1rem 1rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: transparent;
border-radius: .25rem;
}
.alert-danger {
color: #842029;
background-color: #f8d7da;
border-color: #f5c2c7;
}
pre {
display: block;
margin-top: 0;
margin-bottom: 1rem;
overflow: auto;
font-size: .875em;
}
pre code {
font-size: inherit;
color: inherit;
word-break: normal;
}
code {
font-size: .875em;
color: #d63384;
word-wrap: break-word;
}
code, pre {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace, sans-serif;
font-size: 1em;
direction: ltr;
unicode-bidi: bidi-override;
}
</style>
</head>
<body>
<div class="container">
26 changes: 26 additions & 0 deletions Typescript Interface.saBundle/Support/parseTableData.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env ruby
table_name = ARGV[0]

require 'csv'
puts "<pre><code>"
puts "interface #{table_name.split('_').collect(&:capitalize).join} {"
CSV.parse(STDIN.read, headers: true) do |row|
fieldType = "unknown"
# Lots of if statements, couldn't get a shorthand OR to work
fieldType = "string" if row['Type'].include? "text"
fieldType = "string" if row['Type'].include? "char"
fieldType = "Date" if row['Type'].include? "date"
fieldType = "DateTime" if row['Type'].include? "datetime"
fieldType = "number" if row['Type'].include? "fixed"
fieldType = "number" if row['Type'].include? "float"
fieldType = "number" if row['Type'].include? "int"
fieldType = "number" if row['Type'].include? "dec"
fieldType = "number" if row['Type'].include? "doub"
fieldType = "number" if row['Type'].include? "numeric"
fieldType = "number" if row['Type'].include? "year"
fieldType = "boolean" if row['Type'].include? "tinyint"
fieldType = "boolean" if row['Type'].include? "bool"
puts " #{row['Field']}: #{fieldType}"
end
puts "}"
puts "</pre></code>"
32 changes: 32 additions & 0 deletions Typescript Interface.saBundle/Support/processTableData.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env perl -w

while(<>) {

# split tab delimited data
@data = split(/\t/);

$pid = $ENV{"PID"};
$db = $ENV{"DB"};
$res = $ENV{"RES"};
$itemType = "table";

# $data[1] is NULL indicates item is a view
if($data[1] eq "NULL") {
$img = "file://$res/table-view-small-square.tiff";
$itemType = "view";
} else {
$img = "file://$res/table-small-square.tiff";
}

print <<HTML4;
<tr>
<td align=center width='40px'><img src=\"$img\"></td>
<td><a href=\"sequelace://$pid\@passToDoc/SelectDatabase/$db/$data[0]/\" title=\"Click to select $itemType “$db.$data[0]”\">$data[0]</a></td>
<td>$data[1]</td>
<td align=right>$data[4]</td>
<td align=right>$data[6]</td>
<td align=right>$data[11]</td>
<td align=right>$data[12]</td>
</tr>
HTML4
}
89 changes: 89 additions & 0 deletions Typescript Interface.saBundle/command.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>author</key>
<string>Kurt Maine</string>
<key>bundleVersion</key>
<integer>2</integer>
<key>category</key>
<string>Generate</string>
<key>command</key>
<string># Error and SP file handling from bundles by Hans-Jörg Bibiko
# Output the first portion of the HTML file
cat "$SP_BUNDLE_PATH/Support/header.html"
# Check if a table is selected
if [ -z "$SP_SELECTED_TABLE" ]; then
# If no table is selected, output an error to an HTML Tooltip and exit
echo "&lt;div class="alert alert-danger"&gt;Please select a table.&lt;/div&gt;"
exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP
fi
# Remove handshake files before starting
rm -f "$SP_QUERY_RESULT_FILE"
rm -f "$SP_QUERY_FILE"
rm -f "$SP_QUERY_RESULT_STATUS_FILE"
# Query the table description
echo "DESCRIBE \`${SP_SELECTED_TABLE//\`/\`\`}\`" &gt; "$SP_QUERY_FILE"
open "sequelace://$SP_PROCESS_ID@passToDoc/ExecuteQuery/csv"
# Wait for Sequel Ace; status file will be written to disk if query finished
while [ 1 ]
do
[[ -e "$SP_QUERY_RESULT_STATUS_FILE" ]] &amp;&amp; break
sleep 0.1
done
# Check returned status 0 := no error; 1 := error
RES=$(cat "$SP_QUERY_RESULT_STATUS_FILE")
[[ ! -e "$SP_QUERY_RESULT_FILE" ]] &amp;&amp; RES=1
# Check if a SQL error has occured
if [ "$RES" == "0" ]; then
# If no SQL error occured, pipe the result file to the Ruby script
cat "$SP_QUERY_RESULT_FILE" | /usr/bin/ruby "$SP_BUNDLE_PATH/Support/parseTableData.rb" "$SP_SELECTED_TABLE"
else
# If error, message will be saved in result file
echo "&lt;div class="alert alert-danger"&gt;"
cat "$SP_QUERY_RESULT_FILE"
echo "&lt;/div&gt;"
rm -f "$SP_QUERY_RESULT_FILE"
rm -f "$SP_QUERY_FILE"
rm -f "$SP_QUERY_RESULT_STATUS_FILE"
exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP
fi
# Remove handshake files now that we're done
rm -f "$SP_QUERY_RESULT_FILE"
rm -f "$SP_QUERY_FILE"
rm -f "$SP_QUERY_RESULT_STATUS_FILE"
# Output the end of the HTML
echo "&lt;/div&gt;"
echo "&lt;/body&gt;&lt;/html&gt;"
</string>
<key>contact</key>
<string>uggcf://tvguho.pbz/ovaynof/frdhry-npr-glcrfpevcg-ohaqyrf</string>
<key>description</key>
<string>Generate a Typescript interfaces from the currently selected table.
This bundle is not all-encompassing, it is simply meant to save time when creating interfaces. Some manual corrections may need to made to the interface that is generated for you.</string>
<key>keyEquivalent</key>
<string></string>
<key>name</key>
<string>Typescript Interface</string>
<key>output</key>
<string>showashtml</string>
<key>scope</key>
<string>general</string>
<key>tooltip</key>
<string>Generate a Typescript Interace from the currently selected table</string>
<key>uuid</key>
<string>8E6D3915-3FBC-4014-B1F6-059182C3FC11</string>
</dict>
</plist>

0 comments on commit 0158162

Please sign in to comment.