-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jswildcards
committed
Oct 26, 2020
1 parent
7bb1e97
commit 3162cdb
Showing
14 changed files
with
292 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
.git/ | ||
.github/ | ||
.vscode/ | ||
.eggignore | ||
.git | ||
.github | ||
.gitignore | ||
.vscode | ||
CHANGELOG.md | ||
CODE_OF_CONDUCT.md | ||
LICENSE | ||
CONTRIBUTING.md | ||
egg.yml | ||
LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
## [0.0.5] - 2020-10-26 | ||
### Added | ||
- CHANGELOG to log the changes between versions like other standardied open source projects. | ||
- README add badges. | ||
- fs to manage database file system. | ||
- dataset to manage the operations on retrieved data from database. | ||
- sort_and_select example to demonstrate dataset operation. | ||
### Changed | ||
- test cases | ||
- documentations | ||
- now we can use filter functions to select data from database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ files: | |
- ./deps.ts | ||
- ./src/**/* | ||
- ./mod.ts | ||
version: 0.0.4 | ||
version: 0.0.5 | ||
checkAll: true | ||
unlisted: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Document, FileDB } from "../mod.ts"; | ||
|
||
interface User extends Document { | ||
username?: string; | ||
favourites?: string[]; | ||
} | ||
|
||
const db = new FileDB(); | ||
const users = await db.getCollection<User>("users"); | ||
|
||
const compareFavourites = (a: User, b: User) => { | ||
const numberMoreThan = (a.favourites?.length ?? 0) - | ||
(b.favourites?.length ?? 0); | ||
return numberMoreThan / Math.abs(numberMoreThan || 1); | ||
}; | ||
|
||
const compareUsername = (a: User, b: User) => { | ||
const aName = a.username ?? ""; | ||
const bName = b.username ?? ""; | ||
return aName > bName ? 1 : (aName < bName ? -1 : 0); | ||
}; | ||
|
||
users.insertMany([ | ||
{ | ||
username: "foo", | ||
favourites: ["🍎 Apple", "🍐 Pear"], | ||
}, | ||
{ | ||
username: "baz", | ||
favourites: ["🍌 Banana"], | ||
}, | ||
{ | ||
username: "bar", | ||
favourites: ["🍌 Banana"], | ||
}, | ||
]); | ||
|
||
// Test 1: Sort by number of favourites | ||
const value1 = users.find({}).sort(compareFavourites).select(["username"]) | ||
.value(); | ||
|
||
console.log(value1); // "baz", "bar", "foo" | ||
|
||
// Test 2: First sort by number of favourites, then sort by username | ||
const value2 = users.find({}).sort((a, b) => { | ||
const compareResult = compareFavourites(a, b); | ||
if (compareResult) { | ||
return compareResult; | ||
} | ||
return compareUsername(a, b); | ||
}).select(["username"]).value(); | ||
|
||
console.log(value2); // "bar", "baz", "foo" | ||
|
||
// Test 3: First sort by number of favourites in DECENDING order, then sort by username | ||
const value3 = users.find({}).sort((a, b) => { | ||
const compareResult = -compareFavourites(a, b); | ||
if (compareResult) { | ||
return compareResult; | ||
} | ||
return compareUsername(a, b); | ||
}).select(["username"]).value(); | ||
|
||
console.log(value3); // "foo", "bar", "baz" | ||
|
||
db.drop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from "./src/db.ts"; | ||
export * from "./src/collection.ts"; | ||
export * from "./src/types.ts"; | ||
export * from "./src/fs.ts"; | ||
export * from "./src/fsmanager.ts"; | ||
export * from "./src/dataset.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.