fix(repos): use new table name in repo and tests
This commit is contained in:
parent
75155dc536
commit
adba974a4b
4 changed files with 12 additions and 12 deletions
|
|
@ -6,9 +6,9 @@ CREATE TABLE IF NOT EXISTS link (
|
|||
raw TEXT NOT NULL,
|
||||
line INTEGER NOT NULL,
|
||||
col INTEGER NOT NULL,
|
||||
FOREIGN KEY(from_note_id) REFERENCES note(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(from_note_id) REFERENCES note(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_link_from ON links(from_note_id);
|
||||
CREATE INDEX idx_link_target ON links(target_slug);
|
||||
CREATE INDEX idx_link_from ON link(from_note_id);
|
||||
CREATE INDEX idx_link_target ON link(target_slug);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func NewNoteRepository(tx *sql.Tx) NoteRepository {
|
|||
|
||||
func (r *noteRepository) Upsert(ctx context.Context, note *models.Note) error {
|
||||
query := `
|
||||
INSERT INTO notes (id, title, path, slug, created_at, updated_at)
|
||||
INSERT INTO note (id, title, path, slug, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, datetime('now'), datetime('now'))
|
||||
ON CONFLICT (slug) DO UPDATE
|
||||
SET title = EXCLUDED.title,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func (r *tagRepository) Upsert(ctx context.Context, tags []*models.Tag) error {
|
|||
args = append(args, tag.ID(), tag.Name())
|
||||
}
|
||||
|
||||
query := "INSERT OR IGNORE INTO tags(id, name) VALUES " + strings.Join(placeholders, ",")
|
||||
query := "INSERT OR IGNORE INTO tag(id, name) VALUES " + strings.Join(placeholders, ",")
|
||||
|
||||
_, err := r.Transaction.ExecContext(ctx, query, args...)
|
||||
return err
|
||||
|
|
@ -54,7 +54,7 @@ func (r *tagRepository) UpsertNoteTags(ctx context.Context ,noteID string, tagID
|
|||
args = append(args, noteID, tagID)
|
||||
}
|
||||
|
||||
query := "INSERT OR IGNORE INTO note_tags(note_id, tag_id) VALUES " + strings.Join(placeholders, ",")
|
||||
query := "INSERT OR IGNORE INTO note_tag(note_id, tag_id) VALUES " + strings.Join(placeholders, ",")
|
||||
|
||||
_, err := r.Transaction.ExecContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
|
|
@ -77,7 +77,7 @@ func (r *tagRepository) GetByNames(ctx context.Context, names []string) ([]*mode
|
|||
args = append(args, name)
|
||||
}
|
||||
|
||||
query := "SELECT id, name FROM tags WHERE name IN (" + strings.Join(placeholders, ",") + ")"
|
||||
query := "SELECT id, name FROM tag WHERE name IN (" + strings.Join(placeholders, ",") + ")"
|
||||
|
||||
rows, err := r.Transaction.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func TestCreateNoteHandler_NoTemplate_CreatesNoteFileAndReturnsPath(t *testing.T
|
|||
assert.Equal(t, notePath, result)
|
||||
|
||||
var count int
|
||||
require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM notes WHERE slug = ?`, "my-note").Scan(&count))
|
||||
require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM note WHERE slug = ?`, "my-note").Scan(&count))
|
||||
assert.Equal(t, 1, count)
|
||||
|
||||
_, statErr := os.Stat(notePath)
|
||||
|
|
@ -68,10 +68,10 @@ func TestCreateNoteHandler_WithTemplate_CreatesNoteFileWithTagsAndReturnsPath(t
|
|||
assert.Equal(t, notePath, result)
|
||||
|
||||
var noteCount int
|
||||
require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM notes WHERE slug = ?`, "templated-note").Scan(¬eCount))
|
||||
require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM note WHERE slug = ?`, "templated-note").Scan(¬eCount))
|
||||
assert.Equal(t, 1, noteCount)
|
||||
|
||||
rows, err := Fixture.DB.Query(`SELECT name FROM tags WHERE name IN ('go', 'testing')`)
|
||||
rows, err := Fixture.DB.Query(`SELECT name FROM tag WHERE name IN ('go', 'testing')`)
|
||||
require.NoError(t, err)
|
||||
defer rows.Close()
|
||||
|
||||
|
|
@ -112,12 +112,12 @@ func TestCreateNoteHandler_DuplicateSlug_Upserts(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
var count int
|
||||
require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM notes WHERE slug = ?`, "dup-note").Scan(&count))
|
||||
require.NoError(t, Fixture.DB.QueryRow(`SELECT COUNT(*) FROM note WHERE slug = ?`, "dup-note").Scan(&count))
|
||||
assert.Equal(t, 1, count)
|
||||
|
||||
expectedPath := filepath.Join(vaultPath, subDir2, "dup-note.md")
|
||||
var path string
|
||||
require.NoError(t, Fixture.DB.QueryRow(`SELECT path FROM notes WHERE slug = ?`, "dup-note").Scan(&path))
|
||||
require.NoError(t, Fixture.DB.QueryRow(`SELECT path FROM note WHERE slug = ?`, "dup-note").Scan(&path))
|
||||
assert.Equal(t, expectedPath, path)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue