halvardssm / deno-nessie

A modular Deno library for PostgreSQL, MySQL, MariaDB and SQLite migrations
MIT License
527 stars 31 forks source link

[BUG] client.query is not a function #111

Closed willsoto closed 3 years ago

willsoto commented 3 years ago

System (please complete the following information):

deno 1.9.2 (release, x86_64-apple-darwin)
v8 9.1.269.5
typescript 4.2.2

Describe the bug A clear and concise description of what the bug is.

When copying from the examples and running the migration, the following error is thrown:

TypeError: this.client.query is not a function
    at default.up (file:////code/project/migrations/20210507140822-extensions.ts:5:17)
    at ClientPostgreSQL._migrationHandler (https://deno.land/x/nessie@1.2.4/clients/AbstractClient.ts:238:25)
    at async ClientPostgreSQL.migrate (https://deno.land/x/nessie@1.2.4/clients/AbstractClient.ts:100:9)
    at async ClientPostgreSQL.migrate (https://deno.land/x/nessie@1.2.4/clients/ClientPostgreSQL.ts:108:5)
    at async run (https://deno.land/x/nessie@1.2.4/cli.ts:128:11)

To Reproduce Steps to reproduce the behavior:

  1. Create a migration according to examples in readme
  2. Run migrations deno run --allow-net --allow-read --unstable https://deno.land/x/nessie@1.2.4/cli.ts migrate
  3. See error

Expected behavior A clear and concise description of what you expected to happen.

I should be able to run migrations according to the examples.

Screenshots or error log If applicable, add screenshots or error log to help explain your problem.

See above for stack trace

Additional context Add any other context about the problem here.

Migration file that is failing:

import { AbstractMigration } from "https://deno.land/x/nessie@1.2.4/mod.ts";

export default class extends AbstractMigration {
  async up(): Promise<void> {
    await this.client.query(
      'CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;',
    );
  }

  async down(): Promise<void> {
    await this.client.query('DROP EXTENSION IF EXISTS "uuid-ossp"');
  }
}
halvardssm commented 3 years ago

Hi @willsoto ! That is correct, it occurs to me that the docs are not completely clear regarding this. The client is the same client as you specify in the config file, meaning that for postgres, it is the client with the methods specified here. Since v0.6.0 of postgres, the methods are queryArray and queryObject.

Try to change your migration file to such:

import {
  AbstractMigration,
  ClientPostgreSQL,
} from "https://deno.land/x/nessie@1.2.4/mod.ts";

export default class extends AbstractMigration<ClientPostgreSQL> {
  async up(): Promise<void> {
    await this.client.queryArray`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`;
  }

  async down(): Promise<void> {
    await this.client.queryArray`DROP EXTENSION IF EXISTS "uuid-ossp"`;
  }
}

Let me know if this fixes it for you!

willsoto commented 3 years ago

That works! Thanks

ralyodio commented 3 years ago

i'm getting same error for sqlite...how do I fix?