Skip to content

Commit

Permalink
updated readme examples
Browse files Browse the repository at this point in the history
  • Loading branch information
halvardssm committed Jun 4, 2020
1 parent 38076f2 commit 4611b84
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -113,34 +118,30 @@ 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<Schema> = ({ queryBuilder }) => {
queryBuilder.create("users", (table) => {
table.id();
table.string("name", 100).nullable();
table.boolean("is_true").default("false");
table.custom("custom_column int default 1");
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<Schema> = ({ queryBuilder }) => {
return queryBuilder.drop("users");
};
```

Expand Down
2 changes: 1 addition & 1 deletion types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type Info<T = any> = {
export type Migration<T = any> = (
info: Info<T>,
) => string | string[] | Promise<string | string[]>;
export type Seed = Migration;
export type Seed = () => string | string[] | Promise<string | string[]>;
export type LoggerFn = (output?: any, title?: string) => void;
export type QueryWithString = (string: string) => string;
export type AmountMigrateT = number | undefined;
Expand Down

0 comments on commit 4611b84

Please sign in to comment.