Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eveningkid/denodb
MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
https://github.com/eveningkid/denodb
database deno mariadb mongo mongodb mysql orm postgresql sqlite sqlite3
Last synced: about 8 hours ago
JSON representation
MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
- Host: GitHub
- URL: https://github.com/eveningkid/denodb
- Owner: eveningkid
- License: mit
- Created: 2020-05-17T13:31:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-28T10:30:08.000Z (about 1 year ago)
- Last Synced: 2024-12-06T16:08:11.029Z (7 days ago)
- Topics: database, deno, mariadb, mongo, mongodb, mysql, orm, postgresql, sqlite, sqlite3
- Language: TypeScript
- Homepage: https://eveningkid.com/denodb-docs
- Size: 605 KB
- Stars: 1,932
- Watchers: 24
- Forks: 129
- Open Issues: 104
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - denodb
- awesome-deno-cn - @eveningkid/denodb
- awesome-deno - denodb - MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno. (Modules / Database)
- awesome-deno - denodb - 支持MySQL、SQLite、PostgreSQL和MongoDB的ORM。 (模块精选 / 数据库)
- awesome-deno - denodb - 支持多种数据库的ORM,包括MySQL、PostgreSQL和SQLite。 (模块精选 / 常用模块)
README
# DenoDB
**⛔️ This project is not actively maintained: expect issues, and delays in reviews**
- 🗣 Supports PostgreSQL, MySQL, MariaDB, SQLite and MongoDB
- 🔥 Simple, typed API
- 🦕 Deno-ready
- [Read the documentation](https://eveningkid.github.io/denodb-docs)```typescript
import { DataTypes, Database, Model, PostgresConnector } from 'https://deno.land/x/denodb/mod.ts';const connection = new PostgresConnector({
host: '...',
username: 'user',
password: 'password',
database: 'airlines',
});const db = new Database(connection);
class Flight extends Model {
static table = 'flights';
static timestamps = true;static fields = {
id: { primaryKey: true, autoIncrement: true },
departure: DataTypes.STRING,
destination: DataTypes.STRING,
flightDuration: DataTypes.FLOAT,
};static defaults = {
flightDuration: 2.5,
};
}db.link([Flight]);
await db.sync({ drop: true });
await Flight.create({
departure: 'Paris',
destination: 'Tokyo',
});// or
const flight = new Flight();
flight.departure = 'London';
flight.destination = 'San Francisco';
await flight.save();await Flight.select('destination').all();
// [ { destination: "Tokyo" }, { destination: "San Francisco" } ]await Flight.where('destination', 'Tokyo').delete();
const sfFlight = await Flight.select('destination').find(2);
// { destination: "San Francisco" }await Flight.count();
// 1await Flight.select('id', 'destination').orderBy('id').get();
// [ { id: "2", destination: "San Francisco" } ]await sfFlight.delete();
await db.close();
```## First steps
Setting up your database with DenoDB is a four-step process:
- **Create a database**, using `Database` (learn more [about clients](#clients)):
```typescript
const connection = new PostgresConnector({
host: '...',
username: 'user',
password: 'password',
database: 'airlines',
});const db = new Database(connection);
```
- **Create models**, extending `Model`. `table` and `fields` are both required static attributes:```typescript
class User extends Model {
static table = 'users';static timestamps = true;
static fields = {
id: {
primaryKey: true,
autoIncrement: true,
},
name: DataTypes.STRING,
email: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
length: 50,
},
};
}
```- **Link your models**, to add them to your database instance:
```typescript
db.link([User]);
```
- Optional: **Create tables in your database**, by using `sync(...)`:
```typescript
await db.sync();
```
- **Query your models!**
```typescript
await User.create({ name: 'Amelia' });
await User.all();
await User.deleteById('1');
```## Migrate from previous versions
- `v1.0.21`: [Migrate to connectors](docs/v1.0.21-migrations/connectors.md)## License
MIT License — [eveningkid](https://github.com/eveningkid)