6 Commits

Author SHA1 Message Date
9b63877eaa chore(release): v1.0.2 2023-10-04 05:13:46 +03:00
ba845931da chore(release): v1.0.2 2023-10-04 05:11:40 +03:00
3d7503e227 chore: lint 2023-10-03 19:56:52 -06:00
c570597d06 fix: resolve build stuck issue with nitro pre-render enabled (#26) 2023-10-04 04:56:15 +03:00
e7c7beb8fd docs: default connection
close #24
2023-10-03 03:46:23 +03:00
037920620e chore(release): v1.0.1 2023-09-22 01:50:58 +03:00
4 changed files with 51 additions and 6 deletions

View File

@ -1,6 +1,40 @@
# Changelog # Changelog
## v1.0.2
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.1...v1.0.2)
### 🩹 Fixes
- Resolve build stuck issue with nitro pre-render enabled ([#26](https://github.com/arashsheyda/nuxt-mongoose/pull/26))
### 📖 Documentation
- Default connection ([e7c7beb](https://github.com/arashsheyda/nuxt-mongoose/commit/e7c7beb))
### 🏡 Chore
- **release:** V1.0.2 ([ba8459](https://github.com/arashsheyda/nuxt-mongoose/commit/ba8459))
- Lint ([3d7503e](https://github.com/arashsheyda/nuxt-mongoose/commit/3d7503e))
### ❤️ Contributors
- Arash Sheyda <sheidaeearash1999@gmail.com>
- Arash
## v1.0.1
### 🏡 Chore
- **release:** V1.0.0 ([b566196](https://github.com/arashsheyda/nuxt-mongoose/commit/b566196))
- **release:** V1.0.1 ([5bf554f](https://github.com/arashsheyda/nuxt-mongoose/commit/5bf554f))
- Update dependencies ([0f73464](https://github.com/arashsheyda/nuxt-mongoose/commit/0f73464))
### ❤️ Contributors
- Arash Sheyda <sheidaeearash1999@gmail.com>
## v1.0.0 ## v1.0.0
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.9...v1.0.0) [compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.9...v1.0.0)

View File

@ -54,7 +54,12 @@ This function creates a new Mongoose model with schema. Example usage:
| `hooks` | [`(schema: Schema<T>) => void`](https://mongoosejs.com/docs/middleware.html) | false | Schema Hooks Function to customize Model | | `hooks` | [`(schema: Schema<T>) => void`](https://mongoosejs.com/docs/middleware.html) | false | Schema Hooks Function to customize Model |
::alert
you can access the default connection with importing it from mongoose:
::
```
import { connection } from 'mongoose'
```
## `defineMongooseConnection` ## `defineMongooseConnection`
This function creates a new Mongoose connection. This function creates a new Mongoose connection.

View File

@ -1,7 +1,7 @@
{ {
"name": "nuxt-mongoose", "name": "nuxt-mongoose",
"type": "module", "type": "module",
"version": "1.0.1", "version": "1.0.2",
"private": false, "private": false,
"packageManager": "pnpm@8.7.4", "packageManager": "pnpm@8.7.4",
"description": "Nuxt 3 module for MongoDB with Mongoose", "description": "Nuxt 3 module for MongoDB with Mongoose",

View File

@ -8,6 +8,7 @@ import {
import type { ConnectOptions } from 'mongoose' import type { ConnectOptions } from 'mongoose'
import defu from 'defu' import defu from 'defu'
import { join } from 'pathe' import { join } from 'pathe'
import mongoose from 'mongoose'
import { $fetch } from 'ofetch' import { $fetch } from 'ofetch'
import { version } from '../package.json' import { version } from '../package.json'
import { setupDevToolsUI } from './devtools' import { setupDevToolsUI } from './devtools'
@ -18,27 +19,27 @@ export interface ModuleOptions {
* *
* @default process.env.MONGODB_URI * @default process.env.MONGODB_URI
* *
*/ */
uri: string | undefined uri: string | undefined
/** /**
* Nuxt DevTools * Nuxt DevTools
* *
* @default true * @default true
* *
*/ */
devtools: boolean devtools: boolean
/** /**
* Mongoose Connections * Mongoose Connections
* *
* @default {} * @default {}
*/ */
options?: ConnectOptions options?: ConnectOptions
/** /**
* Models Directory for auto-import * Models Directory for auto-import
* *
* @default 'models' * @default 'models'
* *
*/ */
modelsDir?: string modelsDir?: string
} }
@ -54,6 +55,11 @@ export default defineNuxtModule<ModuleOptions>({
options: {}, options: {},
modelsDir: 'models', modelsDir: 'models',
}, },
hooks: {
close: () => {
mongoose.disconnect()
},
},
async setup(options, nuxt) { async setup(options, nuxt) {
if (nuxt.options.dev) { if (nuxt.options.dev) {
$fetch('https://registry.npmjs.org/nuxt-mongoose/latest').then((release) => { $fetch('https://registry.npmjs.org/nuxt-mongoose/latest').then((release) => {