|
| 1 | +# Turso Nextjs Starter |
| 2 | + |
| 3 | +This is a [Next.js] starter template that uses [Turso] to store data and |
| 4 | +[Tailwindcss] for styling. |
| 5 | + |
| 6 | +## Getting Started |
| 7 | + |
| 8 | +Install dependencies: |
| 9 | + |
| 10 | +```bash |
| 11 | +npm install |
| 12 | +``` |
| 13 | + |
| 14 | +Run the development server: |
| 15 | + |
| 16 | +```bash |
| 17 | +npm run dev |
| 18 | +# or |
| 19 | +yarn dev |
| 20 | +# or |
| 21 | +pnpm dev |
| 22 | +``` |
| 23 | + |
| 24 | +Open [http://localhost:3000] with your browser to see the result. |
| 25 | + |
| 26 | +You can start editing the page by modifying `app/page.tsx`. The page |
| 27 | +auto-updates as you edit the file. |
| 28 | + |
| 29 | +This project uses [`next/font`] to automatically optimize and load Inter, a |
| 30 | +custom Google Font. |
| 31 | + |
| 32 | +## Setting up the database |
| 33 | + |
| 34 | +[Install the Turso CLI]. |
| 35 | + |
| 36 | +Create a new turso database. |
| 37 | + |
| 38 | +```sh |
| 39 | +turso db create web-frameworks |
| 40 | +``` |
| 41 | + |
| 42 | +> **Note** |
| 43 | +> |
| 44 | +> We use `web-frameworks` as the database name in this command, but you can give |
| 45 | +> it any name. |
| 46 | +
|
| 47 | +Access the database through the Turso CLI shell. |
| 48 | + |
| 49 | +```sh |
| 50 | +turso db shell web-frameworks |
| 51 | +``` |
| 52 | + |
| 53 | +### Create tables and indexes |
| 54 | + |
| 55 | +Here's the SQL statement to create the `frameworks` table. |
| 56 | + |
| 57 | +```sql |
| 58 | +-- create the "frameworks" table |
| 59 | +create table frameworks ( |
| 60 | + id integer primary key, |
| 61 | + name varchar (50) not null, |
| 62 | + language varchar (50) not null, |
| 63 | + url text not null, |
| 64 | + stars integer not null |
| 65 | +); |
| 66 | +``` |
| 67 | + |
| 68 | +For unique column insertions, add accompanying unique indexes. |
| 69 | + |
| 70 | +```sql |
| 71 | +-- name column unique index |
| 72 | +create unique index idx_frameworks_name ON frameworks (name); |
| 73 | + |
| 74 | +-- url column unique index |
| 75 | +create unique index idx_frameworks_url ON frameworks (url); |
| 76 | +``` |
| 77 | + |
| 78 | +Seed the database with some data. |
| 79 | + |
| 80 | +```sql |
| 81 | +insert into frameworks(name, language, url, stars) values("Vue".js , "JavaScript", "https://github.com/vuejs/vue", 203000); |
| 82 | +insert into frameworks(name, language, url, stars) values("React", "JavaScript", "https://github.com/facebook/react", 206000); |
| 83 | +insert into frameworks(name, language, url, stars) values("Angular", "TypeScript", "https://github.com/angular/angular", 87400); |
| 84 | +insert into frameworks(name, language, url, stars) values("ASP.NET Core", "C#", "https://github.com/dotnet/aspnetcore", 31400); |
| 85 | +insert into frameworks(name, language, url, stars) values("Express", "JavaScript", "https://github.com/expressjs/express", 60500); |
| 86 | +insert into frameworks(name, language, url, stars) values("Django", "Python", "https://github.com/django/django", 69800); |
| 87 | +insert into frameworks(name, language, url, stars) values("Ruby on Rails", "Ruby", "https://github.com/rails/rails", 52600); |
| 88 | +insert into frameworks(name, language, url, stars) values("Spring", "Java", "https://github.com/spring-projects/spring-framework", 51400); |
| 89 | +insert into frameworks(name, language, url, stars) values("Laravel", "PHP", "https://github.com/laravel/laravel", 73100); |
| 90 | +insert into frameworks(name, language, url, stars) values("Flask", "Python", "https://github.com/pallets/flask", 62500); |
| 91 | +insert into frameworks(name, language, url, stars) values("Ruby", "Ruby", "https://github.com/ruby/ruby", 41000); |
| 92 | +insert into frameworks(name, language, url, stars) values("Symfony", "PHP", "https://github.com/symfony/symfony", 28200); |
| 93 | +insert into frameworks(name, language, url, stars) values("CodeIgniter", "PHP", "https://github.com/bcit-ci/CodeIgniter", 18200); |
| 94 | +insert into frameworks(name, language, url, stars) values("CakePHP", "PHP", "https://github.com/cakephp/cakephp", 8600); |
| 95 | +insert into frameworks(name, language, url, stars) values("Qwik", "TypeScript", "https://github.com/BuilderIO/qwik", 16400); |
| 96 | +``` |
| 97 | + |
| 98 | +### Set up Turso on the project |
| 99 | + |
| 100 | +To access the data stored inside your database, you need the Turso database url |
| 101 | +and an authentication token. |
| 102 | + |
| 103 | +To obtain the database url, run the following command: |
| 104 | + |
| 105 | +```sh |
| 106 | +turso db show web-frameworks --url |
| 107 | +``` |
| 108 | + |
| 109 | +And, to create an authentication token for your database, run: |
| 110 | + |
| 111 | +```sh |
| 112 | +turso db tokens create web-frameworks |
| 113 | +``` |
| 114 | + |
| 115 | +Add a `.env.local` file at the root of the project and inside it add the values |
| 116 | +obtained above as the database url and authentication token for your Turso |
| 117 | +database. |
| 118 | + |
| 119 | +``` |
| 120 | +NEXT_TURSO_DB_URL= |
| 121 | +NEXT_TURSO_DB_AUTH_TOKEN= |
| 122 | +``` |
| 123 | + |
| 124 | +## Learn More |
| 125 | + |
| 126 | +To learn more about the stack used in this template, take a look at the |
| 127 | +following resources: |
| 128 | + |
| 129 | +- [Next.js Documentation] - learn about Next.js features and API. |
| 130 | +- [Turso Documentation] - learn about Next.js features and API. |
| 131 | +- [Turso Community] - Join the Turso community. |
| 132 | +- [libSQL] - The open-source open-contribution fork of SQLite Turso is built on. |
| 133 | + |
| 134 | +## Deploy on Vercel |
| 135 | + |
| 136 | +The easiest way to deploy your Next.js app is to use the [Vercel Platform] from |
| 137 | +the creators of Next.js. |
| 138 | + |
| 139 | +[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fturso-extended%2Fapp-turso-nextjs-starter&env=NEXT_TURSO_DB_URL,NEXT_TURSO_DB_AUTH_TOKEN&envDescription=To%20access%20the%20data%20stored%20inside%20your%20database%2C%20you%20need%20the%20Turso%20database%20URL%20and%20an%20authentication%20token.&envLink=https%3A%2F%2Fgithub.com%2Fturso-extended%2Fapp-turso-nextjs-starter%23set-up-turso-on-the-project&repository-name=turso-nextjs-starter&demo-title=Turso%20Nextjs%20Starter&demo-description=This%20is%20a%20Next.js%20starter%20template%20that%20uses%20Turso%20to%20store%20data%20and%20Tailwindcss%20for%20styling%2C%20deployed%20at%20the%20edge.&demo-url=https%3A%2F%2Fturso-nextjs-starter.vercel.app%2F) |
| 140 | + |
| 141 | +Check out the [Next.js deployment documentation] or [Turso's Vercel setup guide] |
| 142 | +for more details. |
| 143 | + |
| 144 | +[Next.js]: https://nextjs.org/ |
| 145 | +[Turso]: https://turso.tech |
| 146 | +[Tailwindcss]: https://tailwindcss.com |
| 147 | +[http://localhost:3000]: http://localhost:3000 |
| 148 | +[`next/font`]: https://nextjs.org/docs/basic-features/font-optimization |
| 149 | +[Install the Turso CLI]:https://docs.turso.tech/reference/turso-cli#installation |
| 150 | +[Next.js Documentation]: https://nextjs.org/docs |
| 151 | +[Turso Documentation]: https://docs.turso.tech/ |
| 152 | +[Turso Community]: https://discord.com/invite/4B5D7hYwub |
| 153 | +[Learn Next.js]: https://nextjs.org/learn |
| 154 | +[libSQL]: https://github.com/libsql/libsql |
| 155 | +[Vercel Platform]: https://vercel.com/new |
| 156 | +[Next.js deployment documentation]: https://nextjs.org/docs/deployment |
| 157 | +[Turso's Vercel setup guide]: https://docs.turso.tech/tutorials/vercel-setup-guide/ |
0 commit comments