chore: progress to insert
This commit is contained in:
@@ -37,6 +37,9 @@ export const insertRows = async ({
|
||||
tableName,
|
||||
});
|
||||
|
||||
// TODO:
|
||||
// What do we do if we want to insert a new row and let default values populate,
|
||||
// but we don't have any values?
|
||||
const [insertedRow] = await adapter.db.insert(adapter.tables[tableName])
|
||||
.values(row).returning();
|
||||
|
||||
|
||||
@@ -190,7 +190,9 @@ export const traverseFields = async ({
|
||||
break;
|
||||
|
||||
default: {
|
||||
targetRow[columnName] = data[columnName];
|
||||
if (typeof data[field.name] !== 'undefined') {
|
||||
targetRow[columnName] = data[field.name];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ export const init: Init = async function init(
|
||||
buildRelationships: true,
|
||||
fields: collection.fields,
|
||||
tableName: collection.slug,
|
||||
timestamps: collection.timestamps,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
index,
|
||||
numeric,
|
||||
PgColumnHKT,
|
||||
timestamp,
|
||||
IndexBuilder,
|
||||
} from 'drizzle-orm/pg-core';
|
||||
import { Field } from 'payload/types';
|
||||
@@ -29,6 +30,7 @@ type Args = {
|
||||
buildRelationships?: boolean
|
||||
fields: Field[]
|
||||
tableName: string
|
||||
timestamps?: boolean
|
||||
}
|
||||
|
||||
type Result = {
|
||||
@@ -41,6 +43,7 @@ export const buildTable = ({
|
||||
buildRelationships,
|
||||
fields,
|
||||
tableName,
|
||||
timestamps,
|
||||
}: Args): Result => {
|
||||
const formattedTableName = toSnakeCase(tableName);
|
||||
const columns: Record<string, AnyPgColumnBuilder> = baseColumns;
|
||||
@@ -87,6 +90,11 @@ export const buildTable = ({
|
||||
relationships,
|
||||
}));
|
||||
|
||||
if (timestamps) {
|
||||
columns.createdAt = timestamp('created_at').defaultNow().notNull();
|
||||
columns.updatedAt = timestamp('updated_at').defaultNow().notNull();
|
||||
}
|
||||
|
||||
const table = pgTable(formattedTableName, columns, (cols) => {
|
||||
return Object.entries(indexes).reduce((acc, [colName, func]) => {
|
||||
acc[colName] = func(cols);
|
||||
|
||||
Reference in New Issue
Block a user