@ez4/database
v0.55.0
Published
EZ4: Components to build database services
Readme
EZ4: Database
The Database contract defines a database service for your application. It uses EZ4's reflection system to analyze your engine, tables, indexes, relations, and scalability configuration, then generates the infrastructure and runtime bindings required to store and query data.
Getting started
Install
npm install @ez4/database @ez4/local-database @ez4/aws-aurora -DYou can use
@ez4/aws-dynamodbinstead of@ez4/aws-aurorafor NoSQL database.
Create database
Here's a minimal example of a database service with a single table.
import type { Client, Database, Index } from '@ez4/database';
import type { PostgresEngine } from '@ez4/aws-aurora/client';
// MyDb table
type MyTableSchema = {
foo: string;
bar: number;
};
// MyDb declaration
export declare class MyDb extends Database.Service<PostgresEngine> {
client: Client<MyDb>;
tables: [
Database.UseTable<{
name: 'test_table';
schema: MyTableSchema;
indexes: {
foo: Index.Primary;
};
}>
];
}See the database service documentation.
Use database
Any handler with access to the database service can perform queries.
import type { Service } from '@ez4/common';
import type { MyDb } from './db';
// Any other handler that has injected MyDb service
export async function anotherHandler(_request: any, { myDb }: Service.Context<AnotherService>) {
// Insert one record
await myDb.test_table.insertOne({
data: {
foo: 'foo',
bar: 123
}
});
// Find one record
const result = await myDb.test_table.findOne({
select: {
bar: true
},
where: {
foo: 'foo'
}
});
}With your database service defined, EZ4 handles provisioning, migrations, scaling, and runtime wiring automatically according to your contract.
What's next
- Database service
- Database table
- Database indexes
- Database relations
- Database engine
- Database streams
- Database handler
- Database listener
- Database client
- Database queries
Examples
- Get started with Aurora RDS
- Get started with DynamoDB
- Aurora RDS CRUDL
- DynamoDB CRUDL
- DynamoDB streams
- Schedule manager
- Storage manager
Providers
License
MIT License
