[SQLITE] Select all by category sqlite, sqlite3 (ok)

C:\Users\Administrator\Desktop\nextjs\openDB.ts

import { open } from 'sqlite'
import sqlite3 from 'sqlite3'
export default async function openDB () {
  return open({
    filename: 'cars.sqlite',
    driver: sqlite3.Database
  })
}

C:\Users\Administrator\Desktop\nextjs\database-test.js

const sqlite = require('sqlite');
const sqlite3 = require('sqlite3');
async function setup() {
  const db = await sqlite.open({
    filename: 'cars.sqlite',
    driver: sqlite3.Database,
  });
  await db.migrate({ force: 'last' });
  const faq = await db.all('SELECT * FROM FAQ ORDER BY createDate DESC');
  console.log('ALL faq', JSON.stringify(faq, null, 2));
  const cars = await db.all('SELECT * FROM Car');
  console.log('ALL CARS', JSON.stringify(cars, null, 2));
}
setup();

C:\Users\Administrator\Desktop\nextjs\pages\index.tsx

export const getServerSideProps: GetServerSideProps = async () => {
  const makes = await getMakes();
  console.log(makes);
  return {
    props: {makes}
  }
}

Kết quả:

Last updated

Was this helpful?