dal/examples/bun/find.test.ts

62 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-09-02 10:37:34 +00:00
import { describe, expect, test } from "bun:test";
import path from "path";
import DAL from "@nesterow/dal/client/native";
2024-09-02 10:37:34 +00:00
// in this case we need to use absolute path
const DATABASE_PATH = path.join(import.meta.dir, "..", "data", "chinook.db");
const db = new DAL({
database: DATABASE_PATH,
});
describe("Query Interface", () => {
test(".Find [find 10 artists whose names start with 'A']", async () => {
2024-09-02 10:37:34 +00:00
const items = db
.In("artists")
.Find({
name: { $glob: "A*" },
})
.Limit(10)
.Rows();
for await (const result of items) {
const [item, error] = result;
2024-09-02 10:37:34 +00:00
console.log(item);
}
expect(true).toBe(true);
});
test(".Find.As [find 5 artists whose names start with 'B'; Represent each row as an Artist object]", async () => {
2024-09-02 10:37:34 +00:00
class Artist {
ArtistId = 0;
Name = "";
}
const items = db
.In("artists")
.Find({
name: { $glob: "B*" },
})
.As(Artist)
.Limit(5)
2024-09-02 10:37:34 +00:00
.Rows();
for await (const result of items) {
const [item, error] = result;
console.log(123, item);
2024-09-02 10:37:34 +00:00
}
const all_rows = await db
.In("artists")
.Find({
name: { $glob: "B*" },
})
.As(Artist)
.Limit(5)
.Query();
2024-09-02 10:37:34 +00:00
expect(true).toBe(true);
});
});