mirror of
				https://github.com/launchbadge/sqlx.git
				synced 2025-10-31 21:42:46 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			515 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			515 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| # JSON Example
 | |
| 
 | |
| ## Setup
 | |
| 
 | |
| 1. Declare the database URL
 | |
| 
 | |
|     ```
 | |
|     export DATABASE_URL="postgres://postgres:password@localhost/json"
 | |
|     ```
 | |
| 
 | |
| 2. Create the database.
 | |
| 
 | |
|     ```
 | |
|     $ sqlx db create
 | |
|     ```
 | |
| 
 | |
| 3. Run sql migrations
 | |
| 
 | |
|     ```
 | |
|     $ sqlx migrate run
 | |
|     ```
 | |
| 
 | |
| ## Usage
 | |
| 
 | |
| Add a person
 | |
| 
 | |
| ```
 | |
| echo '{ "name": "John Doe", "age": 30 }' | cargo run -- add
 | |
| ```
 | |
| 
 | |
| or with extra keys
 | |
| 
 | |
| ```
 | |
| echo '{ "name": "Jane Doe", "age": 25, "array": ["string", true, 0] }' | cargo run -- add
 | |
| ```
 | |
| 
 | |
| List all people
 | |
| 
 | |
| ```
 | |
| cargo run
 | |
| ```
 | 
