-
Notifications
You must be signed in to change notification settings - Fork 0
Update website copy for latest direction #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,10 +1,116 @@ | ||||||
| # Typegres: PostgreSQL, expressed in TypeScript | ||||||
| # Typegres: SQL-over-RPC, Safely | ||||||
|
|
||||||
| [](https://github.com/ryanrasti/typegres/actions/workflows/main.yml) [](https://www.npmjs.com/package/typegres) [](https://opensource.org/licenses/MIT) | ||||||
| [](https://www.npmjs.com/package/typegres) [](https://opensource.org/licenses/MIT) | ||||||
|
|
||||||
| Import the full power of PostgreSQL as a TypeScript library. | ||||||
| A TypeScript API framework that lets clients compose any queries they need within boundaries you control. | ||||||
|
|
||||||
|  | ||||||
| ## Core Principles | ||||||
|
|
||||||
| ### 1. Decouple Your Interface from Your Schema - With All of Postgres, Fully Typed | ||||||
|
|
||||||
| Wrap your tables in a stable, public interface. You can refactor your "private" tables and columns without ever breaking clients. | ||||||
|
|
||||||
| ```typescript | ||||||
| // api.ts | ||||||
| export class User extends Models.User { | ||||||
| // Your public interface stays stable as your schema evolves | ||||||
| createdAt() { | ||||||
| // Before: accessing from JSONB metadata | ||||||
| // return this.metadata['->>'](createdAt).cast(Timestamptz); | ||||||
|
|
||||||
| // After: direct column access (schema refactored) | ||||||
| return this.created_at; | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ```typescript | ||||||
| // route.ts | ||||||
| // Compiles to the single SQL query you'd write manually. | ||||||
| const user = await User.select() | ||||||
| .orderBy((u) => u.createdAt(), { desc: true }) | ||||||
| .limit(1) | ||||||
| .one(tg); | ||||||
| ``` | ||||||
|
|
||||||
| ### 2. Your Interface Defines Your Data Boundaries | ||||||
|
|
||||||
| Allowed operations are just methods on your interface, including relations and mutations. Everything fully composable and typed. | ||||||
|
|
||||||
| ```typescript | ||||||
| // api.ts | ||||||
| export class User extends Models.User { | ||||||
| todos() { | ||||||
| return Todo.select().where((t) => t.user_id.eq(this.id)); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| export class Todo extends Models.Todos { | ||||||
| update({ completed }: { completed: boolean }) { | ||||||
| return update(Todo) | ||||||
| .set((t) => ({ completed })) | ||||||
| .where((t) => t.id.eq(this.id)); | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ```typescript | ||||||
| // route.ts | ||||||
| const user = ... | ||||||
|
|
||||||
| // The only way to get a todo is through a user: | ||||||
| const todo = await user.todos() | ||||||
| .where((t) => t.id.eq(todoId)) | ||||||
| .one(tg); | ||||||
|
|
||||||
| // The only way to update a todo is by getting it from a user: | ||||||
| await todo.update({ completed: true }).execute(tg); | ||||||
| ``` | ||||||
|
|
||||||
| ### 3. Expose your API over RPC, Safely (coming soon) | ||||||
|
|
||||||
| Give clients a composable query builder with your unescapable data boundaries. Compose queries in the client with every Postgres feature (joins, window functions, CTEs, etc.) and function as primitives. | ||||||
|
||||||
| Give clients a composable query builder with your unescapable data boundaries. Compose queries in the client with every Postgres feature (joins, window functions, CTEs, etc.) and function as primitives. | |
| Give clients a composable query builder with your inescapable data boundaries. Compose queries in the client with every Postgres feature (joins, window functions, CTEs, etc.) and function as primitives. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing quotes around the string parameter
'createdAt'in the method call. The code shows:// return this.metadata['->>'](createdAt).cast(Timestamptz);But it should be:
// return this.metadata['->>'](\'createdAt\').cast(Timestamptz);Without quotes,
createdAtwould be treated as a variable reference rather than a string literal.