Durable objects is very similar to DynamoDB
Durable objects is very similar to DynamoDB
number[]s in line 227-230SELECT * FROM TABLE_NAME returns an empty array, whereas I can see the actual data (not empty) on my CF dashboard, and I can query the records correctly using npx wrangler d1 execute site-db --command="SELECT * FROM TABLE_NAME"npx @cloudflare/next-on-pageswrangler commands to use a D1 binding in a next-on-pages application if calling setupDevPlatform in nextConfig?CREATE TABLE query: https://developers.cloudflare.com/api/operations/cloudflare-d1-query-database
Customers table, as you can see with the wrangler query, there is data locally
// This code lives inside a route.tsx file running locally with:
// npm run pages:preview -- --d1 DB=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx
// console.log(await env.DB.prepare(`pragma table_info(TABLE_NAME)`).all());
{
success: true,
meta: {
served_by: 'miniflare.db',
// ...
},
results: [
{
cid: 0,
name: 'id',
type: 'INT AUTO_INCREMENT',
notnull: 0,
dflt_value: null,
pk: 1
},
{
cid: 1,
name: 'url',
type: 'VARCHAR(2048)',
notnull: 1,
dflt_value: null,
pk: 0
},
// ...
// ...[[d1_databases]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "site-db"
database_id = "xxxxxxxxxx-xxxx-xxxx-xxxxxxxxxxx"
preview_database_id = "DB" createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),Customers✘ [ERROR] Failed to log search: Error: D1_ERROR: NOT NULL constraint failed: searchLogs.createdAt
[1]
[1] at D1Database._sendOrThrow (cloudflare-internal:d1-api:66:19)
[1] at async D1PreparedStatement.run (cloudflare-internal:d1-api:172:29)-- Migration number: 0000 2024-01-29T06:07:39.777Z
CREATE TABLE searchLogs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
ip TEXT,
type TEXT NOT NULL CHECK (type IN ('BLID', 'NAME')),
query TEXT NOT NULL
);async function logSearch(DB: D1Database, ip: string, type: string, search: string) {
try {
const logSearchQuery = /*sql*/ `INSERT INTO searchLogs(ip, type, query) VALUES(?, ?, ?)`;
await DB.prepare(logSearchQuery).bind(ip, type.toUpperCase(), search).run();
} catch (error) {
console.error("Failed to log search:", error);
}
}-- Migration number: 0001 2024-02-04T19:30:58.384Z
CREATE TABLE IF NOT EXISTS handles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
auth TEXT NOT NULL,
blid INTEGER NOT NULL,
handle TEXT NOT NULL,
lastSeen DATETIME,
notes TEXT,
UNIQUE(blid, handle)
);
INSERT INTO handles (auth, blid, handle, lastSeen) VALUES ('AAAAA', 0, 'Badspot', datetime('now', '-10 days'));
INSERT INTO handles (auth, blid, handle, lastSeen) VALUES ('ABCDE', 130, 'Space Guy', datetime('now', '-5 days'));
INSERT INTO handles (auth, blid, handle, lastSeen) VALUES ('ABCDE', 130, 'Other Guy', datetime('now', '-3 days'));
INSERT INTO handles (auth, blid, handle, lastSeen) VALUES ('ABCDE', 239, 'Lalam', datetime('now', '-7 days'));