0.29.2
版本发布时间: 2023-12-25 18:26:37
drizzle-team/drizzle-orm最新发布版本:0.34.1(2024-10-08 04:07:09)
Fixes
- Added improvements to the planescale relational tests #1579 - thanks @Angelelz
- [Pg] FIX: correct string escaping for empty PgArrays #1640 - thanks @Angelelz
- Fix wrong syntax for exists fn in sqlite #1647 - thanks @Angelelz
- Properly handle dates in AWS Data API
- Fix Hermes mixins constructor issue
ESLint Drizzle Plugin, v0.2.3
npm i eslint-plugin-drizzle@0.2.3
🎉 [ESLint] Add support for functions and improve error messages #1586 - thanks @ngregrichardson
- Allowed Drizzle object to be or to be retrieved from a function, e.g.
- Added better context to the suggestion in the error message.
New Drivers
🎉 Expo SQLite Driver is available
For starting with Expo SQLite Driver, you need to install expo-sqlite
and drizzle-orm
packages.
npm install drizzle-orm expo-sqlite@next
Then, you can use it like this:
import { drizzle } from "drizzle-orm/expo-sqlite";
import { openDatabaseSync } from "expo-sqlite/next";
const expoDb = openDatabaseSync("db.db");
const db = drizzle(expoDb);
await db.select().from(...)...
// or
db.select().from(...).then(...);
// or
db.select().from(...).all();
If you want to use Drizzle Migrations, you need to update babel and metro configuration files.
- Install
babel-plugin-inline-import
package.
npm install babel-plugin-inline-import
- Update
babel.config.js
andmetro.config.js
files.
babel.config.js
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
+ plugins: [["inline-import", { "extensions": [".sql"] }]]
};
};
metro.config.js
const { getDefaultConfig } = require('expo/metro-config');
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);
+config.resolver.sourceExts.push('sql');
module.exports = config;
- Create
drizzle.config.ts
file in your project root folder.
import type { Config } from 'drizzle-kit';
export default {
schema: './db/schema.ts',
out: './drizzle',
driver: 'expo',
} satisfies Config;
After creating schema file and drizzle.config.ts file, you can generate migrations like this:
npx drizzle-kit generate:sqlite
Then you need to import migrations.js
file in your App.tsx
file from ./drizzle
folder and use hook useMigrations
or migrate
function.
import { drizzle } from "drizzle-orm/expo-sqlite";
import { openDatabaseSync } from "expo-sqlite/next";
import { useMigrations } from 'drizzle-orm/expo-sqlite/migrator';
import migrations from './drizzle/migrations';
const expoDb = openDatabaseSync("db.db");
const db = drizzle(expoDb);
export default function App() {
const { success, error } = useMigrations(db, migrations);
if (error) {
return (
<View>
<Text>Migration error: {error.message}</Text>
</View>
);
}
if (!success) {
return (
<View>
<Text>Migration is in progress...</Text>
</View>
);
}
return ...your application component;
}
1、 drizzle-orm-0.29.2-dist.tgz 624.62KB