mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Rename DittoDatabase to DittoPolyPg
This commit is contained in:
parent
c7624e99d7
commit
5231c8a94f
7 changed files with 22 additions and 21 deletions
|
|
@ -1,6 +0,0 @@
|
|||
import { DittoDatabase } from './DittoDatabase.ts';
|
||||
|
||||
Deno.test('DittoDatabase', async () => {
|
||||
const db = DittoDatabase.create('memory://');
|
||||
await DittoDatabase.migrate(db.kysely);
|
||||
});
|
||||
6
packages/db/adapters/DittoPolyPg.test.ts
Normal file
6
packages/db/adapters/DittoPolyPg.test.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { DittoPolyPg } from './DittoPolyPg.ts';
|
||||
|
||||
Deno.test('DittoPolyPg', async () => {
|
||||
const db = DittoPolyPg.create('memory://');
|
||||
await DittoPolyPg.migrate(db.kysely);
|
||||
});
|
||||
|
|
@ -4,14 +4,15 @@ import path from 'node:path';
|
|||
import { logi } from '@soapbox/logi';
|
||||
import { FileMigrationProvider, type Kysely, Migrator } from 'kysely';
|
||||
|
||||
import { DittoPglite } from './adapters/DittoPglite.ts';
|
||||
import { DittoPostgres } from './adapters/DittoPostgres.ts';
|
||||
import { DittoPglite } from './DittoPglite.ts';
|
||||
import { DittoPostgres } from './DittoPostgres.ts';
|
||||
|
||||
import type { JsonValue } from '@std/json';
|
||||
import type { DittoDB, DittoDBOpts } from './DittoDB.ts';
|
||||
import type { DittoTables } from './DittoTables.ts';
|
||||
import type { DittoDB, DittoDBOpts } from '../DittoDB.ts';
|
||||
import type { DittoTables } from '../DittoTables.ts';
|
||||
|
||||
export class DittoDatabase {
|
||||
/** Creates either a PGlite or Postgres connection depending on the databaseUrl. */
|
||||
export class DittoPolyPg {
|
||||
/** Open a new database connection. */
|
||||
static create(databaseUrl: string, opts?: DittoDBOpts): DittoDB {
|
||||
const { protocol } = new URL(databaseUrl);
|
||||
|
|
@ -51,7 +52,7 @@ export class DittoDatabase {
|
|||
results: results as unknown as JsonValue,
|
||||
error: error instanceof Error ? error : null,
|
||||
});
|
||||
Deno.exit(1);
|
||||
throw new Error('Migration failed.');
|
||||
} else {
|
||||
if (!results?.length) {
|
||||
logi({ level: 'info', ns: 'ditto.db.migration', msg: 'Everything up-to-date.', state: 'skipped' });
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
export { DittoDatabase } from './DittoDatabase.ts';
|
||||
export { DittoPolyPg } from './adapters/DittoPolyPg.ts';
|
||||
|
||||
export type { DittoDB } from './DittoDB.ts';
|
||||
export type { DittoTables } from './DittoTables.ts';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// deno-lint-ignore-file require-await
|
||||
import { DittoDatabase, type DittoDB } from '@ditto/db';
|
||||
import { type DittoDB, DittoPolyPg } from '@ditto/db';
|
||||
import { NPool, NRelay1 } from '@nostrify/nostrify';
|
||||
import { logi } from '@soapbox/logi';
|
||||
|
||||
|
|
@ -19,11 +19,11 @@ export class Storages {
|
|||
public static async database(): Promise<DittoDB> {
|
||||
if (!this._database) {
|
||||
this._database = (async () => {
|
||||
const db = DittoDatabase.create(Conf.databaseUrl, {
|
||||
const db = DittoPolyPg.create(Conf.databaseUrl, {
|
||||
poolSize: Conf.pg.poolSize,
|
||||
debug: Conf.pgliteDebug,
|
||||
});
|
||||
await DittoDatabase.migrate(db.kysely);
|
||||
await DittoPolyPg.migrate(db.kysely);
|
||||
return db;
|
||||
})();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { DittoDatabase } from '@ditto/db';
|
||||
import { DittoPolyPg } from '@ditto/db';
|
||||
import { NostrEvent } from '@nostrify/nostrify';
|
||||
|
||||
import { Conf } from '@/config.ts';
|
||||
|
|
@ -13,9 +13,9 @@ export async function eventFixture(name: string): Promise<NostrEvent> {
|
|||
|
||||
/** Create a database for testing. It uses `DATABASE_URL`, or creates an in-memory database by default. */
|
||||
export async function createTestDB(opts?: { pure?: boolean }) {
|
||||
const db = DittoDatabase.create(Conf.databaseUrl, { poolSize: 1 });
|
||||
const db = DittoPolyPg.create(Conf.databaseUrl, { poolSize: 1 });
|
||||
|
||||
await DittoDatabase.migrate(db.kysely);
|
||||
await DittoPolyPg.migrate(db.kysely);
|
||||
|
||||
const store = new DittoPgStore({
|
||||
db,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { DittoDatabase } from '@ditto/db';
|
||||
import { DittoPolyPg } from '@ditto/db';
|
||||
import '@soapbox/safe-fetch/load';
|
||||
import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/nostrify';
|
||||
import { ReadOnlyPolicy } from '@nostrify/policies';
|
||||
|
|
@ -30,7 +30,7 @@ export class CustomPolicy implements NPolicy {
|
|||
async init({ path, databaseUrl, pubkey }: PolicyInit): Promise<void> {
|
||||
const Policy = (await import(path)).default;
|
||||
|
||||
const db = DittoDatabase.create(databaseUrl, { poolSize: 1 });
|
||||
const db = DittoPolyPg.create(databaseUrl, { poolSize: 1 });
|
||||
|
||||
const store = new DittoPgStore({
|
||||
db,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue