cdcarson / frieda Goto Github PK
View Code? Open in Web Editor NEWJavascript code generator for the PlanetScale serverless driver.
License: MIT License
Javascript code generator for the PlanetScale serverless driver.
License: MIT License
The API has changed a bit since the tests were written (e.g. added ViewDatabase.) Rewrite tests.
The types in frieda-models.ts show up in vscode autocomplete. This should not happen. I think it's because the file does not have a default export.
I think adding
export default {};
to the bottom will fix.
The changes made to the API class names (#6) are not reflected in the generated code. Offending names:
ModelDb, ViewDb
Mainly write tests for the parse functions in app/parse-schema.ts.
In a js project the ModelWhereInput
type is taking the union (??) of Sql
and Partial<M>
rather than inferring that it's a Partial<M>
. See below.
I never noticed this before in typescript project. I'm pretty sure this is a javascript thing, but need to check. In any case the following needs to be looked at. It could probably be improved.
Lines 123 to 126 in e5562ee
Add a "Field Casting" section under "Field Types".
Here's kinda what we want to say, in the broader context of types:
The javascript type of a field determines the casting algorithm. It's up to you to choose an appropriate javascript type for each field. Typing a bigint
column as a number
field makes sense in some circumstances; typing a varchar
column as boolean
will (at least) produce unexpected results.
While writing the docs I realized that the filenames are not really friendly.
schema-definition.d.ts
is where you edit the schema, plus it kinda conflicts with generated/schema-definition.js
*-db
names are not adequately groupedgenerated
if models.d.ts
. (Since it's the only one that deals with type imports.index.js
. There's a potential gotcha -- do we then need to have more d.ts
files? Need to check that.ApplicationDatabase
, ModelsDatabase
and TransactionDatabase
, with matching filenames.So, new structure:
In some cases tooling will overcome this automatically, i.e. allow typescript source code to be consumed in a javascript project. For example, Frieda works fine in a SvelteKit/Vite project using javascript. (I have no idea whether this is the default Vite behavior, or some SvelteKit or Vite setting.)
In other cases there needs to be a build step defined by the user to compile the generated code. It'd be nice to figure this out, and let the user choose to generate javascript automatically.
Documentation for
Too many generated files, which means having to explain/expose too much.
There should be two generated (code) files:
There's no reason to expose these types -- they just make the code readable.
The quick start example has the wrong class names:
ℹ Quick start example:
--------------------------------------------------------
// src/lib/db/get-db.js
// Example quick start code. The `getDb`
// function returns a singleton `AppDb` instance.
import { connect } from '@planetscale/database';
// get the database URL...
import { DATABASE_URL } from '$env/static/private';
// import the generated AppDb class...
import { AppDb } from './generated/app-db';
/** @type {AppDb|undefined} */
let _appDb = undefined;
/** @returns {AppDb} */
export const getDb = () => {
if (!_appDb) {
_appDb = new AppDb(connect({ url: DATABASE_URL }));
}
return _appDb;
};
--------------------------------------------------------
Done in 1358ms. 🦮
Right now in the API we have ViewDb
with find*
methods which we use for database views, extended by ModelDb
which has full on CrUD methods. This is confusing in the docs, since both views and tables are "models".
Also (see #2) we're renaming the generated database classes to *Database
(from *Db
). So, new names for the API databases:
BaseDb
-> BaseDatabase
ViewDb
-> ViewDatabase
ModelDb
-> TableDatabase
Because the types are not exported, eslint warns, e.g...
'Article' is defined but never used.
Fix: add...
/* eslint-disable @typescript-eslint/no-unused-vars */
to the top of the file.
Just link to the docs
Just dump the raw sql.
Right now, there's an option to continue anyway.
frieda/src/lib/app/read-schema-definition-file.ts
Lines 54 to 62 in fa4487d
It should:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.