MCPcopy
hub / github.com/eveningkid/denodb

github.com/eveningkid/denodb @v1.4.0 sqlite

repository ↗ · DeepWiki ↗ · release v1.4.0 ↗
187 symbols 437 edges 30 files 70 documented · 37%
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
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): ```typescript const connection = new PostgresConnector({ host: '...', username: 'user', password: 'password', database: 'airlines', });

const db = new Database(connection); `` - **Create models**, extendingModel.tableandfields` 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

License

MIT License — eveningkid

Extension points exported contracts — how you extend this code

Connector (Interface)
(no doc) [7 implementers]
lib/connectors/connector.ts
Translator (Interface)
(no doc) [4 implementers]
lib/translators/translator.ts
SQLite3Options (Interface)
(no doc)
lib/connectors/sqlite3-connector.ts
MySQLOptions (Interface)
(no doc)
lib/connectors/mysql-connector.ts
PostgresOptionsWithConfig (Interface)
(no doc)
lib/connectors/postgres-connector.ts
PostgresOptionsWithURI (Interface)
(no doc)
lib/connectors/postgres-connector.ts

Core symbols most depended-on inside this repo

formatFieldToDatabase
called by 27
lib/model.ts
where
called by 20
lib/model.ts
table
called by 15
lib/query-builder.ts
toDescription
called by 14
lib/query-builder.ts
_runQuery
called by 11
lib/model.ts
close
called by 11
lib/connectors/connector.ts
query
called by 10
lib/connectors/connector.ts
getComputedPrimaryKey
called by 9
lib/model.ts

Shape

Method 127
Class 36
Function 16
Interface 8

Languages

TypeScript100%

Modules by API surface

lib/model.ts51 symbols
lib/query-builder.ts29 symbols
lib/database.ts16 symbols
lib/connectors/postgres-connector.ts10 symbols
lib/connectors/sqlite3-connector.ts9 symbols
lib/connectors/mysql-connector.ts9 symbols
lib/connectors/connector.ts8 symbols
lib/connectors/mongodb-connector.ts7 symbols
lib/translators/sql-translator.ts6 symbols
lib/relationships.ts6 symbols
tests/units/Relationships/foreignkey.test.ts5 symbols
lib/translators/basic-translator.ts4 symbols

For agents

$ claude mcp add denodb \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact