MyGit

eveningkid/denodb

Fork: 127 Star: 1910 (更新于 1970-01-01 00:00:00)

license: MIT

Language: TypeScript .

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno

最后发布版本: v1.4.0 ( 2023-03-09 09:42:25)

官方网址 GitHub网址

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
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();
// 1

await 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):

    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:

    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:

    db.link([User]);
    
  • Optional: Create tables in your database, by using sync(...):

    await db.sync();
    
  • Query your models!

    await User.create({ name: 'Amelia' });
    await User.all();
    await User.deleteById('1');
    

Migrate from previous versions

License

MIT License — eveningkid

最近版本更新:(数据更新于 1970-01-01 00:00:00)

2023-03-09 09:42:25 v1.4.0

2023-03-09 09:33:10 v1.3.0

2023-01-08 17:45:04 v1.2.0

2022-11-04 10:30:35 v1.1.0

2021-12-14 00:52:02 v1.0.40

2021-08-22 03:18:38 v1.0.39

2021-05-02 04:52:31 v1.0.38

2021-04-29 17:30:14 v1.0.37

2021-04-29 17:23:14 v1.0.36

2021-04-26 21:58:36 v1.0.35

主题(topics):

database, deno, mariadb, mongo, mongodb, mysql, orm, postgresql, sqlite, sqlite3

eveningkid/denodb同语言 TypeScript最近更新仓库

2024-07-03 11:29:30 immich-app/immich

2024-06-27 00:44:20 langfuse/langfuse

2024-06-25 21:34:23 ZuodaoTech/everyone-can-use-english

2024-06-25 02:22:22 typescript-eslint/typescript-eslint

2024-06-25 01:34:15 lobehub/lobe-chat

2024-06-21 17:44:25 janhq/jan