MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / createDatabase

Function createDatabase

apps/web/src/bridge/http-bridge.ts:837–865  ·  view source on GitHub ↗
(
  folder: NoteFolder,
  subpath: string,
  title?: string
)

Source from the content-addressed store, hash-verified

835}
836
837async function createDatabase(
838 folder: NoteFolder,
839 subpath: string,
840 title?: string
841): Promise<DatabaseDoc> {
842 const atRoot = await primaryNotesAtRoot()
843 const baseTitle = (title ?? 'Untitled Database').trim() || 'Untitled Database'
844 const baseName = baseTitle.replace(DB_TITLE_BAD, '-')
845 const dirRel = vaultRelDir(folder, subpath, atRoot)
846 const csvFor = (name: string): string =>
847 csvPathForFormDir(joinSub(dirRel, `${name}${FORM_DIR_SUFFIX}`))
848 // Resolve a non-colliding <Name>.base under the directory.
849 let name = baseName
850 let n = 2
851 while ((await readFileTextOrNull(csvFor(name))) !== null) name = `${baseName} ${n++}`
852 const csvPath = csvFor(name)
853 const folderSub = joinSub(subpath, `${name}${FORM_DIR_SUFFIX}`)
854
855 const idField: DbField = { id: dbGenId(), name: 'id', type: 'text', hidden: true }
856 const nameField: DbField = { id: dbGenId(), name: 'Name', type: 'text' }
857 const fields = [idField, nameField]
858 const { views, activeViewId } = buildDefaultViews(fields, dbGenId)
859 const sidecar: DatabaseSidecar = { version: 1, idFieldId: idField.id, fields, views, activeViewId }
860
861 await createFolder(folder, folderSub)
862 await dbPersistSidecar(csvPath, sidecar)
863 await writeNote(csvPath, serializeRows([], fields))
864 return dbHydrate(csvPath, sidecar, [])
865}
866
867async function createRecordPage(csvPath: string, title: string, body: string): Promise<string> {
868 const formDir = formDirFromCsvPath(dbToPosix(csvPath))

Callers

nothing calls this directly

Calls 12

buildDefaultViewsFunction · 0.90
serializeRowsFunction · 0.90
primaryNotesAtRootFunction · 0.85
vaultRelDirFunction · 0.85
readFileTextOrNullFunction · 0.85
csvForFunction · 0.85
joinSubFunction · 0.85
dbGenIdFunction · 0.85
dbPersistSidecarFunction · 0.85
dbHydrateFunction · 0.85
createFolderFunction · 0.70
writeNoteFunction · 0.70

Tested by

no test coverage detected