Skip to content

Commit

Permalink
Merge pull request #20 from partg952/add-mongoose-snippets
Browse files Browse the repository at this point in the history
Add mongoose snippets
  • Loading branch information
PranavBarthwal authored Oct 9, 2024
2 parents 374ec2d + d6fc6ce commit a5dae83
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,41 @@ This command will create a new file `multer-file-upload.js` in the current worki
export const upload = multer({ storage });

```
5. **`mongoose-con`**:
Sets up a connection to your mongodb using `mongoose`.

**Code Snippet**:
```js
import mongoose from 'mongoose';

function connectToDB(URI) {
mongoose.connect(URI).then(() => {
console.log("Connection to the db succesful");
}).catch(err => {
console.error("An error occcured : ",err);
})
}
export default connectToDB;


```
6. **`mongoose-schema`**:
Sets up a basic schema for your db using `mongoose`.

**Code Snippet**:
```js
import mongoose from 'mongoose';

const schema = new mongoose.Schema({
key:String,
});

const model = mongoose.model("Model",schema);

export default model;

```


### 3. `run generate-ai-snippet <snippetName>`
With the new AI-powered code generation feature, you can generate customized code snippets. For instance, to generate a code snippet for a specific backend functionality, you can run:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backend-generator-cli",
"version": "3.0.3",
"version": "3.0.4",
"main": "index.js",
"type": "module",
"bin": {
Expand Down
10 changes: 10 additions & 0 deletions snippets/mongoose-con.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import mongoose from 'mongoose';

function connectToDB(URI) {
mongoose.connect(URI).then(() => {
console.log("Connection to the db succesful");
}).catch(err => {
console.error("An error occcured : ",err);
})
}
export default connectToDB;
9 changes: 9 additions & 0 deletions snippets/mongoose-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import mongoose from 'mongoose';

const schema = new mongoose.Schema({
key:String,
});

const model = mongoose.model("Model",schema);

export default model;

0 comments on commit a5dae83

Please sign in to comment.