Skip to content

Commit 947a27f

Browse files
committed
improve seed
1 parent 37402a0 commit 947a27f

File tree

22 files changed

+22
-198
lines changed
  • exercises
    • 03.resources
    • 04.prompts
      • 01.problem.prompts/src/db
      • 01.solution.prompts/src/db
      • 02.problem.optimized-prompt/src/db
      • 02.solution.optimized-prompt/src/db
      • 03.problem.completion/src/db
      • 03.solution.completion/src/db
    • 05.sampling

22 files changed

+22
-198
lines changed

exercises/03.resources/01.problem.simple/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

exercises/03.resources/01.solution.simple/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

exercises/03.resources/02.problem.template/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

exercises/03.resources/02.solution.template/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

exercises/03.resources/03.problem.list/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

exercises/03.resources/03.solution.list/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

exercises/03.resources/04.problem.completion/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

exercises/03.resources/04.solution.completion/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

exercises/03.resources/05.problem.linked/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

exercises/03.resources/05.solution.linked/src/db/seed.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ import { DB } from './index.js'
44

55
async function seed() {
66
const dbPath = path.join(process.cwd(), 'db.sqlite')
7-
const dbExists = await fs.stat(dbPath).then(
8-
() => true,
9-
() => false,
10-
)
11-
// delete the db file if it exists
12-
if (dbExists) await fs.unlink(dbPath)
7+
await fs.unlink(dbPath).catch(() => {})
138

149
const db = DB.getInstance(dbPath)
1510

16-
// Helper to run raw SQL (DB class does not expose this, so we use createTag etc. for clearing)
17-
// We'll clear by deleting all entries via getEntries/getTags and deleteEntry/deleteTag
18-
1911
// Delete all entry_tags by deleting entries and tags (should cascade if foreign keys are set)
2012
const entries = await db.getEntries()
2113
for (const entry of entries) {

0 commit comments

Comments
 (0)