• Stars
    star
    1,909
  • Rank 23,368 (Top 0.5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

reacto

A sweet IDE for React.js
JavaScript
855
star
2

react-native-popable

Popovers, tooltips for React Native
TypeScript
318
star
3

pretty-components

Prop-based styled components
JavaScript
43
star
4

react-native-windows-chat-demo

Sample chat application with fake conversations (recoil and RNW)
JavaScript
23
star
5

react-native-xbox-homescreen

Xbox app with homescreen animations
JavaScript
17
star
6

react-native-google-maps

Google Maps animations with Reanimated 2
JavaScript
15
star
7

args-parser

Straight-forward node.js arguments parser
JavaScript
15
star
8

gitfolio

Quickly bootstrap your static portfolio, only using your github data.
JavaScript
14
star
9

react-native-pokedex

An interactive Pokédex UI in React Native
JavaScript
12
star
10

from-react-to-swiftui

Learn SwiftUI from a React point of view
12
star
11

react-native-soundcloud-waveforms

Soundcloud waveforms interaction with Reanimated 2
JavaScript
12
star
12

react-native-dynamic-styles

Dynamic stylesheet and styles for React Native
JavaScript
6
star
13

machinel

Simple Machine learning API for JavaScript (SKlearn-like API)
TypeScript
4
star
14

github-feed

Get notified whenever something happens in someone's github feed
JavaScript
3
star
15

sweet-electron

Easy, minimalist framework for Electron applications
JavaScript
3
star
16

react-pur

React UI component library (using styled-components)
JavaScript
2
star
17

pss-lang

Prop-based StyleSheets for React.js
JavaScript
2
star
18

pretty-loader

Webpack Loader for pretty-components.
JavaScript
2
star
19

eveningkid.github.io

Personal website and projects
HTML
2
star
20

mailteach-contributing

Learn how to contribute to the mailteach project
2
star
21

construct

Graphically creating structural equation models (SEM)
JavaScript
1
star
22

pss-loader

Use PSS syntax with Webpack
JavaScript
1
star
23

jscodeshift

Jscodeshift ES5-bundled
JavaScript
1
star
24

electron-updater-example

Test for electron-updater
JavaScript
1
star
25

search-npm-registry

Search packages/modules among the NPM registry
JavaScript
1
star
26

babel-sass-browserify-boilerplate

🍭 Simple Babel, Sass and Browserify using Gulp.js integration
JavaScript
1
star
27

covid-status

Clean and simple Coronavirus React Native application.
JavaScript
1
star