( folder: NoteFolder, subpath: string, title?: string )
| 835 | } |
| 836 | |
| 837 | async 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 | |
| 867 | async function createRecordPage(csvPath: string, title: string, body: string): Promise<string> { |
| 868 | const formDir = formDirFromCsvPath(dbToPosix(csvPath)) |
nothing calls this directly
no test coverage detected