Skip to content

Commit

Permalink
[examples/basic-example][xs]: @flowershow/markdowndb -> mddb
Browse files Browse the repository at this point in the history
  • Loading branch information
olayway committed Jun 12, 2023
1 parent 5b5f992 commit 31e1476
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 263 deletions.
28 changes: 15 additions & 13 deletions examples/basic-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ MarkdownDB is a javascript library for treating markdown files as a database --
Once we have prepared our markdown files, we can store them (or more precisely - their metadata) in a database, so that we can then query it later for specific project files.

```bash
# npx @flowershow/markdowndb <path-to-folder-with-md-files>
npx @flowershow/markdowndb ./projects
# npx mddb <path-to-folder-with-md-files>
npx mddb ./projects
```

The above command will output a `markdown.db` file in the directory where it was executed. So, in our case the folder structure will look like this:
Expand All @@ -46,6 +46,7 @@ The above command will output a `markdown.db` file in the directory where it was
## Step 3: Explore the SQLite database

Now, let's explore the database. We can do it with any SQLite viewer, e.g. https://sqlitebrowser.org/. When we open the `markdown.db` file in the viewer, we'll see a list of tables:

- `files`: containing metadata of our markdown,
- `file_tags`: containing tags set in the frontmatter of our markdown files,
- `links`: containing wiki links, i.e. links between our markdown files,
Expand All @@ -68,6 +69,7 @@ SELECT * FROM files;
```

Which will output:

```bash
27ce406aac24e59af7a9f3c0c0a437c1d024152b|projects/data-cli.md|md|data-cli||{}
26b1b0b06a4f450646f9e22fc18ec069bf577d8c|projects/datapipes.md|md|datapipes||{}
Expand All @@ -90,16 +92,16 @@ cd projects-list
npm init -y
```

Then, let's install the `@flowershow/markdowndb` package:
Then, let's install the `mddb` package:

```bash
npm install @flowershow/markdowndb
npm install mddb
```

Now, let's create a new file `index.js` and add the following code:

```js
import { MarkdownDB } from "@flowershow/markdowndb";
import { MarkdownDB } from "mddb";

// change this to the path to your markdown.db file
const dbPath = "markdown.db";
Expand All @@ -114,7 +116,7 @@ const client = new MarkdownDB({
const mddb = await client.init();

// get all projects
const projects = await mddb.getFiles()
const projects = await mddb.getFiles();

console.log(JSON.stringify(projects, null, 2));

Expand All @@ -123,7 +125,7 @@ process.exit(0);

Since we're using ES6 modules, we also need to add `"type": "module"` to our `package.json` file.

Before we run the above script, we need to make sure that the `dbPath` variable is pointing to our `markdown.db` file. If you want to store the database outside of your project folder, you can update the `dbPath` variable to point to the correct location. If you want to have it inside your project folder, you can copy it there, or simply re-run the `npx @flowershow/markdowndb <path-to-markdown-folder>` command from within your project folder.
Before we run the above script, we need to make sure that the `dbPath` variable is pointing to our `markdown.db` file. If you want to store the database outside of your project folder, you can update the `dbPath` variable to point to the correct location. If you want to have it inside your project folder, you can copy it there, or simply re-run the `npx mddb <path-to-markdown-folder>` command from within your project folder.

Now, let's run the script:

Expand Down Expand Up @@ -163,7 +165,7 @@ forks: 0
After adding the metadata, we need to re-index our markdown files into the database:

```bash
npx @flowershow/markdowndb ../projects
npx mddb ../projects
```

Now, if we run our script again, we'll see that the `metadata` field in the output contains the metadata we've added to our project files:
Expand Down Expand Up @@ -197,7 +199,7 @@ npm install columnify
And then we'll update our `index.js` file:

```js {2,16-38}
import { MarkdownDB } from "@flowershow/markdowndb";
import { MarkdownDB } from "mddb";
import columnify from "columnify";

const dbPath = "markdown.db";
Expand All @@ -210,7 +212,7 @@ const client = new MarkdownDB({
});

const mddb = await client.init();
const projects = await mddb.getFiles()
const projects = await mddb.getFiles();

// console.log(JSON.stringify(projects, null, 2));

Expand All @@ -224,17 +226,17 @@ const projects2 = projects.map((project) => {

const columns = columnify(projects2, {
truncate: true,
columnSplitter: ' | ',
columnSplitter: " | ",
config: {
description: {
maxWidth: 80,
},
},
});

console.log("\n")
console.log("\n");
console.log(columns);
console.log("\n")
console.log("\n");

process.exit(0);
```
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MarkdownDB } from "@flowershow/markdowndb";
import { MarkdownDB } from "mddb";
import columnify from "columnify";

const dbPath = "markdown.db";
Expand Down
Loading

0 comments on commit 31e1476

Please sign in to comment.