SQLite Explorer
View and interact with your Val Town SQLite data. It's based off Steve's excellent SQLite Admin val, adding the ability to run SQLite queries directly in the interface. This new version has a revised UI and that's heavily inspired by LibSQL Studio by invisal. This is now more an SPA, with tables, queries and results showing up on the same page.
Install
Install the latest stable version (v81) by forking this val:
Authentication
Login to your SQLite Explorer with password authentication with your Val Town API Token as the password.
Todos / Plans
- improve error handling
- improve table formatting
- sticky table headers
- add codemirror
- add loading indication to the run button (initial version shipped)
- add ability to favorite queries
- add saving of last query run for a table (started)
- add visible output for non-query statements
- add schema viewing
- add refresh to table list sidebar after
CREATE/DROP/ALTER
statements - add automatic execution of initial select query on double click
- add views to the sidebar
- add triggers to sidebar
- add upload from SQL, CSV and JSON
- add ability to connect to a non-val town Turso database
- fix wonky sidebar separator height problem (thanks to @stevekrouse)
- make result tables scrollable
- add export to CSV, and JSON (CSV and JSON helper functions written in this val. Thanks to @pomdtr for merging the initial version!)
- add listener for cmd+enter to submit query
valToGH
A utility function for programmatically updating a GitHub repository with code retrieved from a Val.
NOTE: This function currently does not change the contents of a file if it is already present. I will however be adding that functionality.
Usage
Create valimport { valToGH } from 'https://esm.town/v/nbbaier/valToGH';
const repo = "yourGitHubUser/yourRepo";
const val = "valUser/valName"; // or vals = ["valUser/valName1","valUser/valName2", ...]
const ghToken = Deno.env.get("yourGitHubToken");
const result = await valToGH(repo, val, ghToken);
console.log(result);
Parameters
repo
: The GitHub repository in the format{user}/{repo}
.val
: A single repository in the format{user}/{val}
.ghToken
: Your GitHub token for authentication (must have write permission to the target repo)
Options
branch
: Optional target branch. Default ismain
.prefix
: Optional directory path prefix for each file.message
: Optional commit message. Default is the current date and time in the formatyyyy-MM-dd T HH:mm:ss UTC
.ts
: Optional flag to use a.ts
extension for the committed file instead of the default.tsx
.
Val Town AI Readme Writer
This val provides a class ReadmeWriter
for generating readmes for vals with OpenAI. It can both draft readmes and update them directly
PRs welcome! See Todos below for some ideas I have.
Usage
To draft a readme for a given code, use the draftReadme
method:
import { ReadmeWriter } from "https://esm.town/v/nbbaier/readmeGPT";
const readmeWriter = new ReadmeWriter({});
const val = "https://www.val.town/v/:username/:valname";
const generatedReadme = await readmeWriter.draftReadme(val);
To write and update a readme for a given code, use the writeReadme
method:
import { ReadmeWriter } from "https://esm.town/v/nbbaier/readmeGPT";
const readmeWriter = new ReadmeWriter({});
const val = "https://www.val.town/v/:username/:valname";
const successMessage = await readmeWriter.writeReadme(val);
API Reference
Class: ReadmeWriter
The ReadmeWriter
class represents a utility for generating and updating README files.
Constructor
Creates an instance of the ReadmeWriter
class.
Parameters:
model
(optional): The model to be used for generating the readme. Defaults to "gpt-3.5-turbo".apiKey
(optional): An OpenAI API key. Defaults toDeno.env.get("OPENAI_API_KEY")
.
Methods
-
draftReadme(val: string): Promise<string>
: Generates a readme for the given val.-
Parameters:
val
: URL of the code repository.
-
Returns:
- A promise that resolves to the generated readme.
-
-
writeReadme(val: string): Promise<string>
: Generates and updates a readme for the given val.-
Parameters:
val
: URL of the code repository.
-
Returns:
- A promise that resolves to a success message if the update is successful.
-
Todos
- Additional options to pass to the OpenAI model
- Ability to pass more instructions to the prompt to modify how the readme is constructed
SQLite Dump Util
A utility function that generates SQL statements to dump the data and schema of tables in a SQLite database.
Usage
This example specifically dumps the users
table and logs the output:
Create valimport { sqliteDump } from "https://esm.town/v/nbbaier/sqliteDump";
const dump = await sqliteDump(["users"]);
console.log(dump)
You can optionally specify a callback to handle the result. The example below dumps the users
table and emails it using std/email
.
Create valimport { email } from "https://esm.town/v/std/email";
import { sqliteDump } from "https://esm.town/v/nbbaier/sqliteDump";
await sqliteDump(["users"], async (res) => {
await email({ text: res });
});
Function Signature
function sqliteDump(tables?: string[], callback?: ((result: string) => string | void | Promise<void>) | undefined): Promise<string | void>
Parameters
tables
: (Optional) Array of table names to include in the dump. If not provided, all tables will be included.callback
: (Optional) An (potentially async) callback function to process the dump result. The callback receives the dump string as its argument.
Val Town Idea List Aggregator
This val serves as an aggregator for all vals with the tag // @vtIdeas
in their code. To create your own idea list, simple fork this template val and follow the instructions there (instructions can also be found on the the aggregator homepage)
Feature Wish List
Here's some stuff that could be added to this val:
- Pull in the actual lists of ideas from the various aggregated readmes and collect them in a (sortable?) table
- A community list of val ideas, submittable to by form
- Instead of a link list of links, make each Idea List a card, with revealable content
Create an API from a lowdb blob
This val exports a function that takes a lowdb instance and returns a Hono router that can be used to interact with the data. This is the beginning of an implementation of something like json-server for Val Town.
The resulting server also comes with a frontend at /
. The code for the frontend can be found here.
See this val for an example.
Things I'd like to implement
- All HTTP methods
- Custom route definitions (like in json-server)
- Custom frontends
- Filtering, sorting, pagination, etc
The beginnings of a val town implementation of the approach to declarative sqlite migrations laid out in this post: Simple declarative schema migration for SQLite