I think this is acutaly a problem with d1
I think this is acutaly a problem with d1




db-preview name) and I verified they exist with PRAGMA. However, when I use wranger dev, env.DB doesn't have any tables. If I use wrangler dev --remote to connect to production db, it works fine. When I start wranger dev, it shows the correct id in D1 Preview that it gives for db-preview, so where is the disconnect happening here?dev w/o --remote is entirely local--local to d1 execute toorows_written and rows_read in the metadata for every query. Documentation landing soon. e.g.app.get("/api/customers/:name", async (c) => {
const { name } = c.req.param();
const { results } = await c.env.DB.prepare(
// This doesn't work
// "SELECT * FROM Customers WHERE ContactName LIKE '?1%'"
// This works...
"SELECT * FROM Customers WHERE ContactName LIKE 'Maria%'"
)
.bind(name)
.all();
return c.json(results);
})DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS user_key;
DROP TABLE IF EXISTS user_session;
CREATE TABLE user (
id VARCHAR(15) NOT NULL PRIMARY KEY,
username VARCHAR(15) NOT NULL,
name VARCHAR(50) NOT NULL,
userStatus VARCHAR(10) NOT NULL -- student or alumni or faculty or drop-out
);
CREATE TABLE user_key (
id VARCHAR(255) NOT NULL PRIMARY KEY,
user_id VARCHAR(15) NOT NULL,
hashed_password VARCHAR(255),
FOREIGN KEY (user_id) REFERENCES user(id)
);
CREATE TABLE user_session (
id VARCHAR(127) NOT NULL PRIMARY KEY,
user_id VARCHAR(15) NOT NULL,
active_expires BIGINT NOT NULL,
idle_expires BIGINT NOT NULL,
FOREIGN KEY (user_id) REFERENCES user(id)
);
-- basic info table. no need to add fields which exist in user table
DROP TABLE IF EXISTS basic_info;
CREATE TABLE basic_info (
id VARCHAR(15) NOT NULL PRIMARY KEY,
dob VARCHAR(10) NOT NULL,
aadhar VARCHAR(12) NOT NULL,
phone VARCHAR(10) NOT NULL,
houseName VARCHAR(50) NOT NULL,
postOffice VARCHAR(50) NOT NULL,
place VARCHAR(50) NOT NULL,
permanentAddress VARCHAR(50) NOT NULL,
residentialAddress VARCHAR(50) NOT NULL,
pincode VARCHAR(6) NOT NULL,
district VARCHAR(50) NOT NULL,
state VARCHAR(50) NOT NULL,
motherTongue VARCHAR(50) NOT NULL,
bloodGroup VARCHAR(3) NOT NULL,
idMark1 VARCHAR(50) NOT NULL,
idMark2 VARCHAR(50) NOT NULL,
height VARCHAR(5) NOT NULL,
weight VARCHAR(5) NOT NULL,
chronicDisease VARCHAR(50),
familyType VARCHAR(50) NOT NULL,
birthPosition INT NOT NULL,
studentEmail VARCHAR(50) NOT NULL,
FOREIGN KEY (id) REFERENCES user(id)
);DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS user_key;
DROP TABLE IF EXISTS user_session;
CREATE TABLE user (
id VARCHAR(15) NOT NULL PRIMARY KEY,
username VARCHAR(15) NOT NULL,
name VARCHAR(50) NOT NULL,
userStatus VARCHAR(10) NOT NULL -- student or alumni or faculty or drop-out
);➜ wrangler d1 execute db-enam --command "INSERT INTO users(email_address,created_at,deleted,settings) VALUES ('me@example.com,', 1687904983, null, '{}')" --json
[
{
"results": [],
"success": true,
"meta": {
"duration": 0.17432300001382828,
"size_after": 45137920,
"rows_read": 0,
"rows_written": 2 // Two rows: one to the table, and one to the index as there's an index on created_at for this table
}
}
]