diff --git a/README.md b/README.md index 432afb4..3e9e970 100644 --- a/README.md +++ b/README.md @@ -79,24 +79,29 @@ All contributions are welcome, make sure to read the [contributing guideline](./ ## Examples -`nessie.config.ts` +`nessie.config.ts` with all default values ```ts -import { ClientPostgreSQL, nessieConfig } from "https://deno.land/x/nessie/mod.ts"; - -const migrationFolder = "./migrations"; - -const config: nessieConfig = { - client: new ClientPostgreSQL(migrationFolder, { - database: "nessie", - hostname: "localhost", - port: 5432, - user: "root", - password: "pwd", - }), +import { ClientPostgreSQL } from "./clients/ClientPostgreSQL.ts"; + +const nessieOptions = { + migrationFolder: "./db/migrations", + seedFolder: "./db/seeds", +}; + +const connectionOptions = { + database: "nessie", + hostname: "localhost", + port: 5432, + user: "root", + password: "pwd", +}; + +export default { + client: new ClientPostgreSQL(nessieOptions, connectionOptions), + exposeQueryBuilder: false, }; -export default config; ``` Minimal example of a migration file @@ -113,16 +118,14 @@ export const down: Migration = () => { }; ``` -Using the native query builder +Using the native query builder (`exposeQueryBuilder: true`) ```ts import { Migration } from "https://deno.land/x/nessie/mod.ts"; -import { Schema, dbDialects } from "https://deno.land/x/nessie/qb.ts"; +import { Schema } from "https://deno.land/x/nessie/qb.ts"; -const dialect: dbDialects = "mysql" - -export const up: Migration = () => { - const queryArray: string[] = new Schema(dialect).create("users", (table) => { +export const up: Migration = ({ queryBuilder }) => { + queryBuilder.create("users", (table) => { table.id(); table.string("name", 100).nullable(); table.boolean("is_true").default("false"); @@ -130,17 +133,15 @@ export const up: Migration = () => { table.timestamps(); }); - const queryString = new Schema(dialect).queryString( + queryBuilder.queryString( "INSERT INTO users VALUES (DEFAULT, 'Deno', true, 2, DEFAULT, DEFAULT);", ) - queryArray.push(queryString); - - return queryArray + return queryBuilder.query }; -export const down: Migration = () => { - return new Schema(dialect).drop("users"); +export const down: Migration = ({ queryBuilder }) => { + return queryBuilder.drop("users"); }; ``` diff --git a/types.ts b/types.ts index c595e2d..485df7a 100644 --- a/types.ts +++ b/types.ts @@ -8,7 +8,7 @@ export type Info = { export type Migration = ( info: Info, ) => string | string[] | Promise; -export type Seed = Migration; +export type Seed = () => string | string[] | Promise; export type LoggerFn = (output?: any, title?: string) => void; export type QueryWithString = (string: string) => string; export type AmountMigrateT = number | undefined;